求助:如何替换字符串中的反斜杠 想把字符串中的反斜杠(\)替换成(\\)察看了API后知道该用replaceAll(String,String)来替换但是不知道该如何写里面的表达式希望各位指导一下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 字符串中的\只能用两个\\表示(如"abc\\bd"就是表示abc\bd) public class JmTest { public static void main(String[] args) { String s = "abc\\def"; System.out.println(s); String s2 = s.replaceAll("\\\\", "\\\\\\\\"); System.out.println(s2); }} try { String ResultString = SubjectString.replaceAll("\\\\", "\\\\\\\\");} catch (PatternSyntaxException ex) { // Syntax error in the regular expression} catch (IllegalArgumentException ex) { // Syntax error in the replacement text (unescaped $ signs?)} catch (IndexOutOfBoundsException ex) { // Non-existent backreference used the replacement text} 那么为什么replaceAll("\\\\", "\\\\\\\\");是四个和八个呀 因为要转义,下面这样也可以try {String ResultString = SubjectString.replaceAll(@"\\", @"\\\\");} catch (PatternSyntaxException ex) {// Syntax error in the regular expression} catch (IllegalArgumentException ex) {// Syntax error in the replacement text (unescaped $ signs?)} catch (IndexOutOfBoundsException ex) {// Non-existent backreference used the replacement text} 体委replaceAll里面用的是正则表达式,所以字符串转义一次,正则转义一次,所以一个斜扛要写4个,用replaceAll("\\\\", "\\\\\\\\"); 初学多线程,求教(九格子游戏) 关于java反射机制 struts2返回 list 怎样传到Estjs中???? Eclipse-VE下我该如何使用JMenuBar Cannot forward after response has been 问题 java处理图片的问题???????????????????????? tcp socket 求助各位大虾!applet参数运行不起来啊? 如何将自己开发的类打包(生成.jar文件) 一个关于JAVA多平台的实现问题,请高手赐教! 请问,Frame里面可以盛装Applet对象么? 请问如何从一个文件中读取int型的数据,保留到一个2维数组里.
public static void main(String[] args) {
String s = "abc\\def";
System.out.println(s);
String s2 = s.replaceAll("\\\\", "\\\\\\\\");
System.out.println(s2);
}
}
String ResultString = SubjectString.replaceAll("\\\\", "\\\\\\\\");
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
} catch (IllegalArgumentException ex) {
// Syntax error in the replacement text (unescaped $ signs?)
} catch (IndexOutOfBoundsException ex) {
// Non-existent backreference used the replacement text
}
是四个和八个呀
try {
String ResultString = SubjectString.replaceAll(@"\\", @"\\\\");
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
} catch (IllegalArgumentException ex) {
// Syntax error in the replacement text (unescaped $ signs?)
} catch (IndexOutOfBoundsException ex) {
// Non-existent backreference used the replacement text
}