简体   繁体   中英

split integer from string

I'm importing a text file with multiple lines like this

 0     2     23
 1     3     34
 2     4     45
12     5     56

I'm using this to read the file and split the values

while (txtFile.hasNext()) {

    String str = txtFile.nextLine();
    String[] parts = str.split("\\s+");

Based on this regex, the 1st three lines will have parts[1] [2] and [3], when it comes to the 4th line, it becomes parts[0] [1] and [2]

My question is which regex should I use to overcome this problem so it can read part[0] [1] and [2] for all the lines?

修剪输入String的前导空格

String str = txtFile.nextLine().trim();

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