I have a querystring alike value set in a plain string. I started to split string to get value out but I started to wonder that I can proabably write this in one line instead. Could you please advice if there is more optimal way to do this?
I am trying to read "123" and "abc" like in Request.QueryString but from normal string.
protected void Page_Load(object sender, EventArgs e) { string qs = "id=123&xx=abc"; string[] urlInfo = qs.Split('&'); string id = urlInfo[urlInfo.Length - 2]; Response.Write(id.ToString()); }
The ParseQueryString method uses UTF8 format to parse the query string In the returned NameValueCollection, URL-encoded characters are decoded and multiple occurrences of the same query string parameter are listed as a single entry with a comma separating each value.
The value of Request. QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING. You can determine the number of values of a parameter by calling Request. QueryString(parameter). Count.
The node:querystring module provides utilities for parsing and formatting URL query strings. It can be accessed using: const querystring = require('node:querystring');
You can do it this way:
using System.Collections.Specialized; NameValueCollection query = HttpUtility.ParseQueryString(queryString); Response.Write(query["id"]);
Hope it helps.
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