Mike
Mike

Reputation: 2386

Cutting / splitting strings with Java

I have a string as follows:

2012/02/01,13:27:20,872226816,-1174749184,2136678400,2138578944,-17809408,2147352576

I want to extract the number: 872226816, so in this case I assume after the second comma start reading the data and then the following comma end the reading of data.

Example output:

872226816

Upvotes: 0

Views: 263

Answers (2)

user647772
user647772

Reputation:

s = "2012/02/01,13:27:20,872226816,-1174749184,2136678400,2138578944,-17809408,2147352576";
s.split(",")[2];

Javadoc for String.split()

Upvotes: 8

npinti
npinti

Reputation: 52185

If the number you want will always be after the 2nd comma, you can do something like so:

String str = "2012/02/01,13:27:20,872226816,-1174749184,2136678400,2138578944,-17809408,2147352576";
String[] line = str.split(",");
System.out.println(line[2]);

Upvotes: 1

Related Questions