What is the .Net equivalent of jscript escape/unescape?

G

Guest

Is there a set of methods in the .Net framework that do the same thing as the
jscript functions escape and unescape?

I get very close with HttpUtility.UrlEncodeUnicode, but it puts "+" for
spaces instead of "%20". Uri.EscapeString seems to create the correct escape
string, but there is no unescape. The function is not public anyway, so I
probably shouldn't use it.

I need a way to escape text on the client, and then unescape it on the
server, and then escape it on the server, and unescape it out on the client.
How can I do this? Thanks.
 
G

Guest

Hello,
Because UrlEncode gets very close, I wrote my own methods that just wraps
that and adds some extra functionality (like replacing the apostrophe ' to
avoid cross-site-scripting warnings).

I provide sample code and charts of what UrlEncode escapes at this blog entry:
http://timstall.dotnetdevelopersjournal.com/read/1092094.htm

For example:

public static string UrlFullEncode(string strUrl)
{
if (strUrl == null)
return "";
strUrl = System.Web.HttpUtility.UrlEncode(strUrl);
return strUrl.Replace("'",_strApostropheEncoding);
}
private const string _strApostropheEncoding = "%27";

public static string UrlFullDecode(string strUrl)
{
if (strUrl == null)
return "";
strUrl = strUrl.Replace(_strApostropheEncoding,"'");
return System.Web.HttpUtility.UrlDecode(strUrl);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top