0

I have a string which basically looks like this:

/giveaway/host/setup/ref=aga_h_su_dp?_encoding=UTF8&value_id=1484778065

The trick here is that the length of the string can vary and will change... However the part with "value_id=something" always stays same... So the problem that I ran in was that I can do something like this:

var myId = string.SubString(30,45);

to get the value after value_id= /*this one here*/

I'm thinking that this can be solved by regex or some other way, but I'm not too sure how to write such one. Can someone help me out?

User987
  • 3,663
  • 15
  • 54
  • 115

2 Answers2

1

Could you try this. If your value_id always the last of your string you can use this.

var str = "/giveaway/host/setup/ref=aga_h_su_dp?_encoding=UTF8&value_id=1484778065";

var valueId = str.Split('=').LastOrDefault();

Result : 1484778065

Hope it's help to you

arslanaybars
  • 1,813
  • 2
  • 24
  • 29
0

You can split by 'value_id='

string[] tokens = str.Split(new[] { "value_id=" }, StringSplitOptions.None);

if(tokens.Length>1){
   //parse tokens[1] with the value
}
farbiondriven
  • 2,450
  • 2
  • 15
  • 31