Parsing a fixed-width formatted file in Java

后端 未结 10 2024
遥遥无期
遥遥无期 2020-11-28 10:51

I\'ve got a file from a vendor that has 115 fixed-width fields per line. How can I parse that file into the 115 fields so I can use them in my code?

My first thought

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 11:21

    If your string is called inStr, convert it to a char array and use the String(char[], start, length) constructor

    char[] intStrChar = inStr.toCharArray();
    String charfirst10 = new String(intStrChar,0,9);
    String char10to20 = new String(intStrChar,10,19);
    

提交回复
热议问题