javascript escape special characters except non english
I have a problem with unescaping non-english characters.
For Example,
var text1 = "ABC Farmacéutica Corporation".
text1 = escape(text1);
output: ABC%20Farmac%E9utica%20Corporation
But I would like to escape only special characters other than non-english characters like é. Do we have a开发者_StackOverflow社区ny logic for these characters to be ignored?
Please help, Thanks in advance.
The escape function returns the text escaped in the Unicode format. Space is represented as %20 (hexadecimal). If I understand you correctly you don't want to escape é, in this case, only the space character. The only way I can see this is possible is that you have a table containing those non-english characters that you don't want to be escaped and refer to it. Something like this:
var dontEscape = "éöå....and_so_on";
var text = "ABC Farmacéutica Corporation";
var escaped = "";
for (var i = 0; i < text.length; i++) {
var test = text.substring(i, i+1); // charAt is unsafe with unicode chars
escaped = test.indexOf(test.toLowerCase()) == -1 ? escape(test) : test;
}
Is there any special reason for why you want to escape characters selectively?
精彩评论