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
public class strReplace{ public static void main(String args[]){ String str="abcdefgfgf"; str=str.replace('f',' '); System.out.println(str); } }
public class strReplace{ public static void main(String args[]){ String str="abcdefgfgf"; str=str.replace('f',' '); System.out.println(str); String v="f"; try{ str="abcdefgfgf"; str=str.replaceAll(v,str); System.out.println(str); }catch(java.util.regex.PatternSyntaxException e){ e.printStackTrace(); } } }raplaceAll怎么用,看不明白,谢谢有人能指导吗???
一不小心打错字了
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
public static void main(String args[]){
String str="abcdefgfgf";
str=str.replace('f',' ');
System.out.println(str); }
}
public static void main(String args[]){
String str="abcdefgfgf";
str=str.replace('f',' ');
System.out.println(str);
String v="f";
try{
str="abcdefgfgf";
str=str.replaceAll(v,str);
System.out.println(str);
}catch(java.util.regex.PatternSyntaxException e){
e.printStackTrace();
}
}
}raplaceAll怎么用,看不明白,谢谢有人能指导吗???
晕,看明白了,以v代替str; 如 替换空格
mystring.replaceAll("[\r\n]","<br>");
不能用replaceAll
还有我用replace是把一个字符替换为空字符,不是空格!!!
String.replace('f',str);
试一下可不可以
if(null=="")
你可以测试一下"a"+""+"b";的结果。好像没有必要这样吧?如果真的需要给特出的东西留下空间可以用自定一个。str=str.replaceAll(v,"");看看能不能用。我的机器没有这个函数。实在不行就自己写一个吧,反正也好写。