473,734 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Url EncodeUnicode, but it puts "+" for
spaces instead of "%20". Uri.EscapeStrin g 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 3193
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(s tring strUrl)
{
if (strUrl == null)
return "";
strUrl = System.Web.Http Utility.UrlEnco de(strUrl);
return strUrl.Replace( "'",_strApostro pheEncoding);
}
private const string _strApostropheE ncoding = "%27";

public static string UrlFullDecode(s tring strUrl)
{
if (strUrl == null)
return "";
strUrl = strUrl.Replace( _strApostropheE ncoding,"'");
return System.Web.Http Utility.UrlDeco de(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.Url EncodeUnicode, but it puts "+" for
spaces instead of "%20". Uri.EscapeStrin g 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
7734
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 for this. I tried xml.sax.saxutils.unescape(s), but while it works with '&', it doesn't work with '0' and other numeric codes. Any suggestions on how to decode the numeric xml escape codes such as this? Thanks. -- To reply to me directly,...
6
5019
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 also contain escaped octal or hex such as \001 or \x09. The escapes are coming into sys.argv without shell interpretation. Do I need to use the compile module to make this work? Any suggestions? ===
1
19540
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: Response.Cookies("Lines")("URL4") = escape("http://www.ASP101.com") Gives the following result:
2
14478
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. JavaScripts escape() function converts all non-alphanumerical chars to %xx, and all unicode chars to %uxxxx (where xxxx is unicode charcode). I'd like to have C# function that get this escaped string back to normal at the server side. Perhaps there...
10
8352
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 that in asp.net? Seems like escape server side function is no longer provided in asp.net, or am I missing something here?
2
28233
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 serializes text to an XML file and then deserializes back to text. If the user enters XML illegal text like "<Actor1>", the code properly escapes it to "&lt;Actor1&gt;", something that doesn't interfere with the XML syntax, and writes it into the Xml...
4
4279
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 line with \n\t\t\t\thello\t\t\n would hve the string 'hello' in it. In others words, is there a method of removing all escape sequences from a string? I've tried Regex.Unescape(string) but this doesn't not seem to remove the
1
7630
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 back into "<em>". I mean a function like the following would do the job but is there a more JS-native solution? html = html.replace(/&/g, "&amp;");
1
4186
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 escape codes. (I hope I can describe my issue here without having to worry about how to escape it for display on this group!) On the server-side I extract some text from an XML file, which includes some style and content. The XML is simply:
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.