I have a csv file and some of the text in it is as follows:
sendLink, 23, VL_name1, 0.5, 0.5
PATH, (device_1, 1, SW1, 10),\
(SW_2, 23, SW_1, 23),\
(SW_1, 9, device_2, 1)
PATH, (device_3, 2, SW_12, 10),\
(SW_12, 23, SW_11, 23),\
(SW_11, 9, device_2, 2)
sendLink, 24, VL_name2, 0.5, 0.5
PATH, (device_4, 1, SW_09, 24),\
(SW_01, 9, device_2, 1)
PATH, (device_5, 2, SW_19, 24),\
(SW_11, 9, device_2, 2)
sendLink, 25, VL_name3, 0.5, 0.5
PATH, (device_7, 1, SW_09, 24),\
(SW_09, 17, SW_01, 24),\
(SW_01, 9, device_2, 1)
PATH, (device_8, 2, SW_19, 24),\
(SW_19, 17, SW_11, 24),\
(SW_11, 9, device_2, 2)
I am using Qt and have fetched all the data from the csv into a QStringList where each element of QStringList is one line from the csv.
I have defined a struct like below:
typedef struct{
QString outputESResource;
QString inputESResource;
} Path_t;
and now my intention is to scan though the QString list and for every line that starts with sendLink, I should read the immediate next lines that start with PATH
, save the second element(device_1, device_3) into outputESResource
and then look in the lines after the PATH line and fetch the before last column (device_2) in this example and save it into inputESResource
.
For this, I am searching through the stringList for lines starting with PATH as follows:
for(int i=0; i < fileContents.count(); i++)
{
if(fileContents[i].startsWith("PATH", Qt::CaseSensitive) )
{
//scan next element in stringlist
}
}
I am not sure if this is the right way to implement this. Could someone please advice on it.