Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is an implementation which uses very basic language features. It's part of a class which we have to port and maintain in Objective C so we choose to have more lines of code but easier to port and understand by a programmer that isn't very familiar with C#. </p> <pre><code> /// &lt;summary&gt; /// Builds a complete http url with query strings. /// &lt;/summary&gt; /// &lt;param name="pHostname"&gt;&lt;/param&gt; /// &lt;param name="pPort"&gt;&lt;/param&gt; /// &lt;param name="pPage"&gt;ex "/index.html" or index.html&lt;/param&gt; /// &lt;param name="pGetParams"&gt;a Dictionary&lt;string,string&gt; collection containing the key value pairs. Pass null if there are none.&lt;/param&gt; /// &lt;returns&gt;a string of the form: http://[pHostname]:[pPort/[pPage]?key1=val1&amp;key2=val2...&lt;/returns&gt; static public string buildURL(string pHostname, int pPort, string pPage, Dictionary&lt;string,string&gt; pGetParams) { StringBuilder sb = new StringBuilder(200); sb.Append("http://"); sb.Append(pHostname); if( pPort != 80 ) { sb.Append(pPort); } // Allows page param to be passed in with or without leading slash. if( !pPage.StartsWith("/") ) { sb.Append("/"); } sb.Append(pPage); if (pGetParams != null &amp;&amp; pGetParams.Count &gt; 0) { sb.Append("?"); foreach (KeyValuePair&lt;string, string&gt; kvp in pGetParams) { sb.Append(kvp.Key); sb.Append("="); sb.Append( System.Web.HttpUtility.UrlEncode(kvp.Value) ); sb.Append("&amp;"); } sb.Remove(sb.Length - 1, 1); // Remove the final '&amp;' } return sb.ToString(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload