I am new to C++ and I am trying to use the Qt framework to create an app, however, I need to parse a big text file, struggling with the split() option.
I am trying to split each line into 6 pieces, each string is not the same length, so not sure if I can use the mid(), left() or right() functions ?
For example, in Java, I can easily do it with a max split, like this, it allows me to split into 6 pieces, keep the white spaces in the last substring:
String str = "1 689 0 0 02WA Aaaa Bbbb Ccccc";
String str2 = "1 6389 0 0 02WAB Eeee Ff Ggggggggg";
System.out.println("First line");
for(int i=0; i < 6; i++){
System.out.println(str.split("\\s+", 6)[i]);
}
System.out.println("\nSecond line");
for(int i=0; i < 6; i++){
System.out.println(str2.split("\\s+", 6)[i]);
}
Output:
First line
1
689
0
0
02WA
Aaaa Bbbb Ccccc
Second line
1
6389
0
0
02WAB
Eeee Ff Ggggggggg
The problem is, if I knew the exact length of each sub string I want, I could use left(),right() or mid() I guess, but they change line by line, so I never know.
Is there any way I can achieve this in Qt the same as Java does ?