开发者

Java - splitting a string onto a new string?

开发者 https://www.devze.com 2023-04-09 18:04 出处:网络
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:

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消