Is there an C# equivalent to the PHP function parse_str?
I couldn't find anything and wrote my own function but is there something in the C# framework?
public Dictionary<string, string> parse_str(string query) {
Dictionary<string, string> data = new Dictionary<string, string>();
foreach(string set in query.Trim('?').Split('&'))
data.Add(set.Split('=')[0], set.Split('=').Length < 2 ? "" : set.Split('=')[1]);
return data;
}
I think you are looking for HttpUtility.ParseQueryString()
If you're taking it from the browser's query string, you can use Request.QueryString
You can get a list of all the keys: Request.QueryString.Keys
Get a value of a key: Request.QueryString["KeyName"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With