Well, the piece of code in my class :
String sentence = "1. John," +
"2. Mark," +
"3. Sam";
And is logical that I have this output :
1. John
2. Mark
3. Sam
, so I need to replace all commas to line breaks ( \n ) ;
Well, the piece of code in my class :
String sentence = "1. John," +
"2. Mark," +
"3. Sam";
And is logical that I have this output :
1. John
2. Mark
3. Sam
, so I need to replace all commas to line breaks ( \n ) ;
Unless I have missed something, this is as simple as using replace
to change the command toa newline character (\n
):
String sentence = "1. John," +
"2. Mark," +
"3. Sam";
String newSentence = sentence.replace(",", "\n");
Depending upon environment, you may want to use a carriage-return\line-feed which would be "\r\n"
.
Here's a link to a few examples of using it.
You literally just replace , with \n:
String sentence = "1. John\n" +
"2. Mark\n" +
"3. Sam";