title: Does C# have an equivalent to JavaScript's encodeURIComponent()?
body: <p>In JavaScript:</p>
  
  <pre><code>encodeURIComponent("©√") == "%C2%A9%E2%88%9A"
  </code></pre>
  
  <p>Is there an equivalent for C# applications? For escaping HTML characters I used:</p>
  
  <pre><code>txtOut.Text = Regex.Replace(txtIn.Text, @"[\u0080-\uFFFF]",
      m =&gt; @"&amp;#" + ((int)m.Value[0]).ToString() + ";");
  </code></pre>
  
  <p>But I'm not sure how to convert the match to the correct hexadecimal format that JS uses. For example this code:</p>
  
  <pre><code>txtOut.Text = Regex.Replace(txtIn.Text, @"[\u0080-\uFFFF]",
      m =&gt; @"%" + String.Format("{0:x}", ((int)m.Value[0])));
  </code></pre>
  
  <p>Returns "<code>%a9%221a"</code> for <code>"©√"</code> instead of <code>"%C2%A9%E2%88%9A"</code>. It looks like I need to split the string up into bytes or something.</p>
  
  <p>Edit: This is for a windows app, the only items available in <code>System.Web</code> are: <code>AspNetHostingPermission</code>, <code>AspNetHostingPermissionAttribute</code>, and <code>AspNetHostingPermissionLevel</code>.</p>