I am currently passing a parameter to a SQL string like this –
grid=0&
And I am using a RegEx to get the 0 value like so-
Match match = Regex.Match(input, @"grid=([A-Za-z0-9\-]+)\&$",
RegexOptions.IgnoreCase);
string grid = match.Groups[1].Value;
which works perfectly.
However as development has progressed it is clear that more parameters will be added to the string like so-
grid=0&hr=3&tb=0
These parameters may come in a different order in the string each time so clearly the RegEx I am currently using wont work. I have looked into it and think Split may be an option however not sure.
What would the best method be and how could I apply it to my current problem?
If you’re parsing query string and looking for an alternative to
Regex, there is a specialized class and method for that, it returns collection of parameters:You have to include
System.Webnamespace.You can access each of the parameters’ values by using it’s key: