Atitit.js string content escape js processing HTML
1. js processing HTML problem 1
2. js string content escape 1
2.1. Process Flow 1
3. The following table lists the remaining special characters, which can be added to a text string using a backslash: 2
4.--code 2
1. jsprocessingHTMLthe problem
Anti-slash problem
Quotation mark problem. The statement interruption issue caused by carriage return:
2. jsthe string content escaped
A carriage return
There's a newline escape.
One quote escape:
Anti-Slash escape
2.1. Processing process
Replace the backslash first. In quotation marks, in carriage return, in line break:
Author:: Old Wow's paw attilax Ayron, email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax
3. The following table lists the remaining special characters that can be added to a text string using a backslash:
Code |
Output |
\‘ |
Single quotation marks |
\" |
Double quotes |
\& |
and number |
\\ |
Back slash |
\ n |
Line break |
\ r |
Carriage return character |
\ t |
Tabs |
\b |
Backspace |
\f |
Page break |
4.--code
Public class encodex {
Public static void main (string[] args) {
String s = "Window.document.getElementById" (' Editor '). value= ' \ "aaa\" ' " ;
s =filex. Read ("C:\\1.txt");
System. out . println (jsencode( s));
}
Public static string Jsencode (String p2_txt) {
// TODO auto-generated Method Stub
String Doublequoto = "\"" ;
String ReplaceAll = P2_txt . ReplaceAll (doublequoto, "\\\\\");
return replaceall;
}
Public static string jsencodesinglequoue ( string p2_ TXT) {
// TODO auto-generated Method Stub
P2_txt = P2_txt . Replace ("\ \", "\\\\");
String doublequoto="\";
String replaceall = p2_txt. ReplaceAll (doublequoto, "\ \\\\ ' ");
replaceall = replaceall. ReplaceAll ("\ r"), "\\\\r");
replaceall = replaceall. ReplaceAll ("\ n", "\\\\ N ");
return replaceall;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Atitit.js string content escape JS processing html