I want to get some Strings out of a text file. I know how to get the whole String of a text file with
QTextStream Stream (GEO);
QString text;
do
{
text = Stream.readLine();
}
while(!text.isNull());
That works fine to get all the text under the QString text, but I just need some specific strings out of the text,schematically like:
if the text "start" appears in the Qstring text (or the QTextStream Stream)
save the following text under QString First
until the text "end" appears
Can someone tell me how to do this or maybe even give me a small example?
One thing you can use is to get the indexes of the "start" and "end" with indexOf() and the just use:
or midRef if you dont want to create a new list. You might have to handle "end" aswell, otherwise you might go from 0 to -1 which wouldnt return anything. Maybe (end > start ? end : start)
Edit: Nevermind. If end == -1 that just means that it will return everything until the end (per default the second parameter is -1). If you don’t want this you can go with my example instead and use some kind of if-statement when choosing the "end"
Edit: Noticed that I missread the doc and this will def. work:
This produces the following resoults. The last two numbers are where "start" ends and "end" begins.
Or you can do it by using regEx. Wrote a very simple snippet here for you:
This works even if you done have "end" in the end, then it just parse to the end of the line. Enjoy!