日期:2014-05-20 浏览次数:21002 次
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("\\\\.*", "")); //正则表达式
}
}
------解决方案--------------------
String str="asdd//sdfsd//sdf "; str=str.replaceAll("//.*",""); System.out.println(str);