简体   繁体   中英

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
s = "2012/02/01,13:27:20,872226816,-1174749184,2136678400,2138578944,-17809408,2147352576";
s.split(",")[2];

Javadoc for String.split()

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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM