public static String formatForEmail(String context) {
if (context == null) {
return null;
}
context = replace(context, "<", "&lt;");
context = replace(context, ">", "&gt;");
context = replace(context, "\"", "&quot;");
context = replace(context, "''", "&#039;");
context = replace(context, " ", "&nbsp;");
context = replace(context, "\r\n", "<br>");
context = replace(context, "\r", "<br>");
context = replace(context, "\n", "<br>"); return context;
}为什么格式化''的时候,要用&#039;啊,这个&#039;是什么意思啊?谢谢大家

解决方案 »

  1.   

    字符转义:一般字符。除   .$   ^   {   [   (   ¦   )   *   +   ?\   外,其他字符与自身匹配。如果在   []   字符类中,则与退格符   \u0008   匹配;将   ASCII   字符匹配为八进制数(最多三位);在后面带有不识别为转义符的字符时,与该字符匹配。注意   转义字符   \b   是一个特例。\a   响铃(BEL)   007   \b   退格(BS)   008   \f   换页(FF)   012   \n   换行(LF)   010   \r   回车(CR)   013   \t   水平制表(HT)   009   \v   垂直制表(VT)   011   \\   反斜杠   092   \?   问号字符   063   \‘   单引号字符   039   \"   双引号字符   034   \0   空字符(NULL)   000   \ddd   任意字符   三位八进制   \xhh   任意字符   二位十六进制。