In JavaScript:
encodeURIComponent("©√") == "%C2%A9%E2%88%9A"
Is there an equivalent for C # applications? To escape 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 hex 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 seems like I need to split the string into bytes or something like that.
Edit: this is a Windows application, the only elements available on System.Web are: AspNetHostingPermission , AspNetHostingPermissionAttribute and AspNetHostingPermissionLevel .
travis Sep 17 '08 at 19:05 2008-09-17 19:05
source share