I have a line in a file which is like this:
DEF PatientLoadView Group {
I am trying to parse the file to get the word after the word “DEF” in the above line.
I am trying to find split the line using string.split() and then use indexOf function of QStringList class to find the index of “DEF” and then get the word next to it. But the indexOf function returns -1 for this line. For other such lines, it returns correct value. What could be the problem?
My code is as follows:
QString line = in.readLine();
if(line.contains("DEF"))
{
QStringList lineSplit = line.split(" ");
int index = lineSplit.indexOf("DEF",0);
QString nodeName = lineSplit[index+1];
I found the cause of the problem – the line starts with a tab ‘\t’ and that was being part of the string that I read in. Removing this tab character worked fine for me and I am now able to get the correct results.
Thank you for the help.