String x="fsdaf\r\n24342";
x=x.replaceAll("\\r","");
如果要去掉空格,\t,\r,\n这些所有东西就用
x=x.replaceAll("[\\s]*","");
x=x.replaceAll("\\r","");
如果要去掉空格,\t,\r,\n这些所有东西就用
x=x.replaceAll("[\\s]*","");
调试欢乐多
x=x.replace('4','8');
也无效果,x还是原来的x,怎么回事?
x=x.replaceAll("\\r","");
如果要去掉空格,\t,\r,\n这些所有东西就用
x=x.replaceAll("[\\s]*","");
你看清楚哦
是replaceAll
而且都是双引号
JDK2A的帮助文档里面也没有这个方法的,请楼上验证.
你看我的java 1.4的doc
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
NullPointerException - if regex is null
Since:
1.4
See Also:
Pattern
//x的值:kkkkklllkkky=x.replace('l','m');
//x的值:kkkkklllkkk, y的值:kkkkkmmmkkk