title: Count QueryString Key in string of URL
body: <p>I want to count how many query string key appear in a string of URL. The URL here is an string so I can't use Request.QueryString.AllKeys to count how many key in the url. Currently, I have an solution for this by analyze the structure of url string and using count string within a string to count query string keys in an url string. Everyone can look clearly in my sample of code:</p>
  
  <pre><code>public int CountQueryStringKey(string urlString)
  {
      string urlWithoutKey = urlString.Substring(0, urlString.IndexOf("?"));
      string allKeyString = urlString.Substring(urlString.IndexOf("?") + 1);
      string[] allKeyAndValue = allKeyString.Split('&amp;');
      return allKeyAndValue.Length;
  }
  </code></pre>
  
  <p>It is simple but not enough. What will happen if there is no query string key in string of url, and there are always different kind of url which I'm not sure it's structure.</p>
  
  <p>I need some help for a good solution in this issue.</p>