js操作字符串时,如果字符串中存在换行符"\n”时会出现
错误,下面给出解决办法。
js端解决办法:
function getzfc(str)
{
if(str != null){
str = str=str.replace(/^\n+|\n+$/g,"<br />");
}
return str;
}
java端解决办法:
public static String MyReplace(String mystr)
{
if(mystr != null)
{
mystr = mystr.replace("\r\n", "<br/>");
mystr = mystr.replace("'", " ");
mystr = mystr.replace("\r", "<br/>");
mystr = mystr.replace("\n", "<br/>");
mystr = mystr.replace("\t", " ");
mystr = mystr.replace(" ", " ");
//mystr = mystr.Replace("<","<");
//mystr = mystr.Replace(">",">");
//mystr = mystr.Replace("&","&");
}
return mystr;
}