首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

怎样删除字符串中的"\\"以及"\\"后的内容,该如何解决

2012-01-06 
怎样删除字符串中的\\以及\\后的内容如题[解决办法]Java codeprivate static void test(){String test

怎样删除字符串中的"\\"以及"\\"后的内容
如题

[解决办法]

Java code
    private static void test(){        String test = "123\\456";        String str = test.substring(0, test.indexOf("\\"));        System.out.println(str);    }
[解决办法]
String tes = "asdd//sdfsd//sdf";
String res = (tes.split("//"))[0];
[解决办法]
import java.util.regex.*;

public class Hello {
public static void main(String[] args) {
String str = "I am a boy, \\and I love beauty!\\haha";
//运用正则表达式
Pattern p = Pattern.compile("\\\\.*");
Matcher m = p.matcher(str);
System.out.println(m.replaceAll(""));
}
}
[解决办法]
import java.util.regex.*;

public class Hello {
public static void main(String[] args) {
String str = "I am a boy, \\and I love beauty!\\haha";
System.out.println(str.replaceAll("\\\\.*", "")); //正则表达式
}
}
[解决办法]
HTML code
        String str="asdd//sdfsd//sdf ";         str=str.replaceAll("//.*","");        System.out.println(str); 

热点排行
Bad Request.