Redian新闻
>
java str.replaceAll("\n", "") doesn't work
avatar
java str.replaceAll("\n", "") doesn't work# Java - 爪哇娇娃
f*g
1
另一本正在筹备的新书中的两首童谣+插画。。Redy and Bluey系列~~
插画我画的,诗是别的作者写的哈~~~之前没有接触太多的nursery rhymes,贴上来大
家看看~~~欢迎拍砖~~
One, two, peek-a-boo
Red, blue, I see you.
Tiny faces behind the leaves,
Skip, jump, trick and tease.
Secret spaces, secret places,
explore among the many mazes.
Stalks and stems-they do bend,
With love and care, we do tend.
One, two, peek-a-boo
Red, blue, I see you.
Redy and Bluey rode a great big whale
With moons for eyes and a giant tail
Across the starlit sky so bright
Dreaming dreams all through the night
They looked below and saw the homes
So colourful and small like gnomes
Redy and Bluey laughed and sang
Even through the midnight rain
They loved the sparkling ocean and stars
They spoke of the moon, Venus and Mars
And when their twilit ride was done
They slept until the morning sun.
avatar
l*n
2
I want to put multi-lines input into single line, but str.replaceAll("\n", ""
) doesn't work
What's the right command?
Thanks
avatar
i*a
3
太忙了,赞,先沙发~

【在 f**********g 的大作中提到】
: 另一本正在筹备的新书中的两首童谣+插画。。Redy and Bluey系列~~
: 插画我画的,诗是别的作者写的哈~~~之前没有接触太多的nursery rhymes,贴上来大
: 家看看~~~欢迎拍砖~~
: One, two, peek-a-boo
: Red, blue, I see you.
: Tiny faces behind the leaves,
: Skip, jump, trick and tease.
: Secret spaces, secret places,
: explore among the many mazes.
: Stalks and stems-they do bend,

avatar
a*w
4
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

avatar
f*g
5
谢谢伊伊~~你先忙哈 ~~
等有更多诗再来贴一些~~

【在 i***a 的大作中提到】
: 太忙了,赞,先沙发~
avatar
t*a
6
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

avatar
w*i
7
真棒
avatar
l*n
8
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.
avatar
w*m
9
mm的花,一如既往的引一人瞩目。

【在 f**********g 的大作中提到】
: 另一本正在筹备的新书中的两首童谣+插画。。Redy and Bluey系列~~
: 插画我画的,诗是别的作者写的哈~~~之前没有接触太多的nursery rhymes,贴上来大
: 家看看~~~欢迎拍砖~~
: One, two, peek-a-boo
: Red, blue, I see you.
: Tiny faces behind the leaves,
: Skip, jump, trick and tease.
: Secret spaces, secret places,
: explore among the many mazes.
: Stalks and stems-they do bend,

avatar
e*t
10
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.

avatar
h*a
11
赞!
, peek-a-boo
avatar
g*g
12
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.

avatar
t*a
13
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.

avatar
f*n
14
不要用replaceAll。用replace就行啦:
str.replace("\n", "")
avatar
e*t
15
对,readline是主要问题。

【在 t***a 的大作中提到】
: readline是只读一行,每行后面的\n被它吃掉了,不在结果中了
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。