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被它吃掉了,不在结果中了
|