我试了一下,replaceAll方法的第二个参数好像不支持正则表达式,所以不能用一个replaceAll就能完成,写个类就行了:
public class Tools
{
public static String trans(String str)
{
String temp = "";
temp = str.replaceAll("\'","@Q");
temp = temp.replaceAll("\"","@SQ");
temp = temp.replaceAll("\n","@RN");
return temp;
}
public static void main(String[] args)
{
String str = "saj啊\'啊\"啊\n啊da adfsdf asdf \nsdf";
System.out.println("Tools : str = " + str);
String str1 = trans(str);
System.out.println("Tools : str1 = " + str1);
}}
public class Tools
{
public static String trans(String str)
{
String temp = "";
temp = str.replaceAll("\'","@Q");
temp = temp.replaceAll("\"","@SQ");
temp = temp.replaceAll("\n","@RN");
return temp;
}
public static void main(String[] args)
{
String str = "saj啊\'啊\"啊\n啊da adfsdf asdf \nsdf";
System.out.println("Tools : str = " + str);
String str1 = trans(str);
System.out.println("Tools : str1 = " + str1);
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货