String replaceStr="--\\t--";
String str ="你\\t的";
str=str.replaceAll("\\t",replaceStr);
System.out.println(str);
str=str.replaceAll("--t--","\\\\t");
System.out.println(str);
\\\\t是替换成“hello\\tworld”
\\t是替换时找到\\t
\t是匹配“hello\tworld”
本文详细介绍了如何使用Java进行字符串的替换操作,通过实例演示了如何将特殊字符 替换为自定义字符串,再将其还原的过程。文章展示了使用replaceAll方法进行字符串替换的具体语法,并解释了 、\t和\\t在替换过程中的不同作用。
1009

被折叠的 条评论
为什么被折叠?



