Basically I have a string list, and want it converted into a integer array.
Here’s what I’m doing:
for(int q =0; q < fileData[selectedIndex].length(); q++)
{
if(tempString[q] != ',')
{
if(twoChars[1] == ',')
{
numVals[count] = twoChars.toInt();
qDebug() << numVals[count] << "new val dbl ";
count++;
}
else
{
numVals[count] = tempString[q].digitValue();
qDebug() << numVals[count] << "new val";
count++;
}
}
}
Code values explained:
tempString is my string, and in this case holds 1,3,8,11.
numVals is my integer array, and im using count to keep track of where to store the next value into the array.
(the logic in my code is that i’m looking for commas, and if I find one that means the value before is a digit, however as you can probably already imagine this doesn’t work for two digit numbers)
I attempted to use twoChars(stores two values from the original string as my 2 digit number, but this also doesnt work as it still only looks for commas.
Leaving me with array values of 1,3,8,1,1 –> my 11 is getting separated into two 1’s
SOrton is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3