由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - java str.replaceAll("\n", "") doesn't work
相关主题
JAVA文本文件读写问题java 截取一部分string
有没有 replaceall for String?我自己编了个Java面试题
wrong!!! Re: 有没有 replaceall for String?如何确保每次读入的字符串都是unique的
Re: wrong!!! Re: 有没有 replaceall for StriRe: 请教一个问题...
why doesn't replaceAll work?问几个菜问题2
问个String:replaceALL的问题What does this mean?
问一个Java regexp的题Eclipse不能保存UTF-8文件?
有什么办法高效的进行replaceAllrock paper scissor 求教
相关话题的讨论汇总
话题: replaceall话题: work话题: doesn话题: java话题: what
进入Java版参与讨论
1 (共1页)
l****n
发帖数: 55
1
I want to put multi-lines input into single line, but str.replaceAll("\n", ""
) doesn't work
What's the right command?
Thanks
a*w
发帖数: 4495
2
str.replaceAll("\r\n|\r|\n", "");
换行符可能不是"\n"

""

【在 l****n 的大作中提到】
: I want to put multi-lines input into single line, but str.replaceAll("\n", ""
: ) doesn't work
: What's the right command?
: Thanks

t***a
发帖数: 416
3
replaceAll("\\n", "")
因为replaceAll是正则表达式,所以两次转义

""

【在 l****n 的大作中提到】
: I want to put multi-lines input into single line, but str.replaceAll("\n", ""
: ) doesn't work
: What's the right command?
: Thanks

l****n
发帖数: 55
4
Thanks.
I tried
s = infile.readLine()
s = infile.readLine().replaceAll("\\n+", "")
s = infile.readLine().replaceAll("[\n\r\t]+", "")
s = infile.readLine().replaceAll("\r\n|\r|\n", "")
s = infile.readLine().replaceAll("\\n", "")
It's very strange that none of them work.
e*****t
发帖数: 1005
5
charAt一个一个拿,看到底是什么。

【在 l****n 的大作中提到】
: Thanks.
: I tried
: s = infile.readLine()
: s = infile.readLine().replaceAll("\\n+", "")
: s = infile.readLine().replaceAll("[\n\r\t]+", "")
: s = infile.readLine().replaceAll("\r\n|\r|\n", "")
: s = infile.readLine().replaceAll("\\n", "")
: It's very strange that none of them work.

g*****g
发帖数: 34805
6
because you shouldn't readLine() for what you want to do, you should read
the entire file as a string.

【在 l****n 的大作中提到】
: Thanks.
: I tried
: s = infile.readLine()
: s = infile.readLine().replaceAll("\\n+", "")
: s = infile.readLine().replaceAll("[\n\r\t]+", "")
: s = infile.readLine().replaceAll("\r\n|\r|\n", "")
: s = infile.readLine().replaceAll("\\n", "")
: It's very strange that none of them work.

t***a
发帖数: 416
7
readline是只读一行,每行后面的\n被它吃掉了,不在结果中了

【在 l****n 的大作中提到】
: Thanks.
: I tried
: s = infile.readLine()
: s = infile.readLine().replaceAll("\\n+", "")
: s = infile.readLine().replaceAll("[\n\r\t]+", "")
: s = infile.readLine().replaceAll("\r\n|\r|\n", "")
: s = infile.readLine().replaceAll("\\n", "")
: It's very strange that none of them work.

f*******n
发帖数: 12623
8
不要用replaceAll。用replace就行啦:
str.replace("\n", "")
e*****t
发帖数: 1005
9
对,readline是主要问题。

【在 t***a 的大作中提到】
: readline是只读一行,每行后面的\n被它吃掉了,不在结果中了
1 (共1页)
进入Java版参与讨论
相关主题
rock paper scissor 求教why doesn't replaceAll work?
Re: How can I call another program from Java?问个String:replaceALL的问题
如何输出TXT文件?问一个Java regexp的题
怎么从键盘输入整数或float?有什么办法高效的进行replaceAll
JAVA文本文件读写问题java 截取一部分string
有没有 replaceall for String?我自己编了个Java面试题
wrong!!! Re: 有没有 replaceall for String?如何确保每次读入的字符串都是unique的
Re: wrong!!! Re: 有没有 replaceall for StriRe: 请教一个问题...
相关话题的讨论汇总
话题: replaceall话题: work话题: doesn话题: java话题: what