Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# extract values from key-value pairs in string

i have a string like this:

blablablamorecontentblablabla?name=michel&score=5&age=28&iliedabouttheage=true

looks like a regular query string yes, but i'm not in any web context

now i want to extract the values (after the = sign) by their key , for example,what is the name (michel), the score(5), the age(28) etc.

Normally i parse the string like get the position in the string of the word 'name', then add 5 to it (length of 'name=') and name this position 'start' then search for the &-sign and name that position 'end', and then get the string between the position start and end.

But there must be a better solution, is this a regex thing?

like image 335
Michel Avatar asked Jan 12 '10 12:01

Michel


1 Answers

Try System.Web.HttpUtility.ParseQueryString, passing in everything after the question mark. You would need to use the System.Web assembly, but it shouldn't require a web context.

like image 168
Eric Petroelje Avatar answered Oct 27 '22 00:10

Eric Petroelje