Moe
Moe

Reputation: 470

How to extract a specific string line

I have two elements in my string and I would like to take the second element and put in a new string.

String data;

The data string contains:

27 Nov 2012
30 Oct 2012

The two dates are separated by \n.

Any help is appreciated :)

Upvotes: 1

Views: 114

Answers (2)

squiguy
squiguy

Reputation: 33370

Another way to do it:

String dates[] = data.split("\n");
String second = dates[1];

Upvotes: 4

awolfe91
awolfe91

Reputation: 1647

String first = data.substring(0, data.indexOf("\n"));
String second = data.substring(data.indexOf("\n"));

Hope that helps!

Upvotes: 4

Related Questions