Java - splitting a string onto a new string?
E.g.
String s = "You should always brush your teeth before every meal in the day.";
but I want do split part of it into a new sentence like so:
String s = "You should always brush your teeth/nbefore every meal in the day.";
so the result is this:
String s = "You should always brus开发者_JAVA技巧h your teeth";
String s2 = "before every meal in the day.";
Basically, I want it to search for the "/n" and then separate the next sentence from the present one.
String[] str = s.split("/n");
if(str.length == 2) {
s = str[0];
s2 = str[1];
}
You can split your string into an array of strings doing
String[] chunks = s.split("\\n");
精彩评论