问关于x=x.replace('\r',' ');

tangqiuzheng 2005-02-24 01:44:27
String x="fsdaf\r\n24342";
x=x.replace('\r',' ');

我希望得到什么大家一看就知道,可是事与愿违,为什么?
...全文
1165 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangqiuzheng 2005-02-24
  • 打赏
  • 举报
回复
我用的是jdk 1.3
tangqiuzheng 2005-02-24
  • 打赏
  • 举报
回复
明白了,一方面保存文件与时间的关系.

此外:

x="kkkklllkkk";

x.replace('l','m');
//x的值:kkkkklllkkk

y=x.replace('l','m');
//x的值:kkkkklllkkk, y的值:kkkkkmmmkkk
jFresH_MaN 2005-02-24
  • 打赏
  • 举报
回复
晕,我无语了,楼主的jdk版本肯定是低于1。4
你看我的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
tangqiuzheng 2005-02-24
  • 打赏
  • 举报
回复
啊;我把题目问个清楚,我的意思是想用replace把一个字符串里面的某个字符全部替换成另一个字符,但是替换通过编译,却在执行的时候仍然没有替换.

我的JB中没有replaceAll方法,楼上的兄弟,用的不是标准的JDK,你用了什么开发包,导入了replaceAll方法?
JDK2A的帮助文档里面也没有这个方法的,请楼上验证.
jFresH_MaN 2005-02-24
  • 打赏
  • 举报
回复
String x="fsdaf\r\n24342";
x=x.replaceAll("\\r","");
如果要去掉空格,\t,\r,\n这些所有东西就用
x=x.replaceAll("[\\s]*","");


你看清楚哦
是replaceAll
而且都是双引号
tangqiuzheng 2005-02-24
  • 打赏
  • 举报
回复
这应该是个SCJP程序员考试的讲义,可是不记不清楚了
tangqiuzheng 2005-02-24
  • 打赏
  • 举报
回复
在线等
wucr 2005-02-24
  • 打赏
  • 举报
回复
dvafdsafdsafdsa
tangqiuzheng 2005-02-24
  • 打赏
  • 举报
回复
那么我改一改,
x=x.replace('4','8');
也无效果,x还是原来的x,怎么回事?
jFresH_MaN 2005-02-24
  • 打赏
  • 举报
回复
呵呵,你不相信我啊??
我是替换成空的啊,就是"",双引号中间没东西
tangqiuzheng 2005-02-24
  • 打赏
  • 举报
回复
是不是啊?replace哪能用双引号作参数呀?
jFresH_MaN 2005-02-24
  • 打赏
  • 举报
回复
String x="fsdaf\r\n24342";
x=x.replaceAll("\\r","");
如果要去掉空格,\t,\r,\n这些所有东西就用
x=x.replaceAll("[\\s]*","");

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧