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