Bob Let
Bob Let

Reputation: 123

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 brush 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.

Upvotes: 2

Views: 119

Answers (2)

Tobias
Tobias

Reputation: 9380

String[] str = s.split("/n");
if(str.length == 2) {
    s = str[0];
    s2 = str[1];
}

Upvotes: 2

tilo
tilo

Reputation: 14169

You can split your string into an array of strings doing

String[] chunks = s.split("\\n");

Upvotes: 0

Related Questions