public class Test2 { public static void main(String[] src){ String father = new String("1234567890abcdefghijk"); String sun = new String("678905");
if(father.indexOf(sun) != -1){
father = father.replaceAll(sun,""); System.out.println(father); } else{ System.out.println("不是子串!"); } } }测试有效
管他在不在,repalceAll replaceAll public String replaceAll(String regex, String replacement) Replaces each substring of this string that matches the given regular expression with the given replacement. An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters: regex - the regular expression to which this string is to be matched Returns: The resulting String Throws: PatternSyntaxException - if the regular expression's syntax is invalid Since: 1.4
public static void main(String[] src){
String father = new String("1234567890abcdefghijk");
String sun = new String("678905");
if(father.indexOf(sun) != -1){
father = father.replaceAll(sun,"");
System.out.println(father);
}
else{
System.out.println("不是子串!");
}
}
}测试有效
replaceAll
public String replaceAll(String regex,
String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.
An invocation of this method of the form str.replaceAll(regex, repl) yields exactly the same result as the expression Pattern.compile(regex).matcher(str).replaceAll(repl)Parameters:
regex - the regular expression to which this string is to be matched
Returns:
The resulting String
Throws:
PatternSyntaxException - if the regular expression's syntax is invalid
Since:
1.4