473,383 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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

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.
Nov 19 '05 #1
1 3167
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.dotnetdevelopersjour...ad/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);
}

"Harry Keck" wrote:
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.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Daniel | last post by:
I'm working with strings that contain xml escape codes, such as '0' and need a way in python to unescape these back to their ascii representation, such as '&' but can't seem to find a python method...
6
by: Paul Watson | last post by:
How can I get the escapes from a command line parameter interpreted? The user provides a string on the command line. The string might contain traditional escapes such as \t, \n, etc. It might...
1
by: JigMan | last post by:
When chucking data in a cookie you cannot use certain characters (in this example ‘ : ‘ ). To get around this you use escape and unescape. Trying to use the escape as such: ...
2
by: Pavils Jurjans | last post by:
Hello, I am looking fow C# equivalent of JavaScripts escape() and unescape() functions. I need to use C# function at the server side and then be able to use the opposite at the client side. ...
10
by: Danny | last post by:
In the classic asp, I can use escape built-in function (server side function) like this: <script language=javascript> var myContent = unescape(<%=escape(strContent)%>) </script> How do I do...
2
by: Richard Lewis Haggard | last post by:
Is it possible to use features from XmlDocument to unescape text back to its original raw text format after it has been escaped to handle non-HTML compliant character strings? I have code that...
4
by: JJ | last post by:
Is there a way of checking that a line with escape sequences in it, has no strings in it (apart from the escape sequences)? i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it a...
1
by: Philipp | last post by:
How do I convert a string to escaped HTML? (Let's say I'm not using DOM.) E.g. "<p>foo</p>" would become "&lt;p&gt;foo&lt;/p&gt;"? Reversely, how do I unescape a string to be HTML? E.g. "&lt;em&gt;" would turn...
1
by: RK | last post by:
Perhaps I'm confused somwhere in my understanding, but I'm trying to deal with some escaped text from an XML file which includes html markup and it appears there are a couple of techniques for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.