Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是代码:
String text = "hello, my name, is john smith.";
我如何使它成为:
String text = "hello\n my name\n is john smith.";
谢谢!
text = text.replace(',', '\n');
使用 replaceAll 方法:
text.replaceAll(",","\n");
用这个:
text = text.replace(", ", "\n");
注意:第一个参数是逗号后跟一个空格。它将用新行替换逗号和它后面的空格。这样看起来好多了,除非你一开始就想要空格。