Incrementing String value
-
wrote on 18 Jan 2019, 04:26 last edited by
Well this is my JSON value
"INKA010101002020"
which is in QByteArray, where I've converted it to QString for substring of last 3 digits "020" then I need to add 1 (auto increment +1) to that 3 digit one, where I've converted it to 'int' but didn't work so any suggestions ?? -
Well this is my JSON value
"INKA010101002020"
which is in QByteArray, where I've converted it to QString for substring of last 3 digits "020" then I need to add 1 (auto increment +1) to that 3 digit one, where I've converted it to 'int' but didn't work so any suggestions ??@Vineela Something like
QString str = "INKA010101002020"; QString subStr = str.right(3); int number = subStr.toInt(); ++number; str = str.chopped(3) + QString("%1").arg(number, 3, 10, '0');
-
@Vineela Something like
QString str = "INKA010101002020"; QString subStr = str.right(3); int number = subStr.toInt(); ++number; str = str.chopped(3) + QString("%1").arg(number, 3, 10, '0');
-
@jsulm well this was my answer
INKA01010100221.000000000000000000000000000000000000000000000000
I wanted 021 only the last three digits to get added -
@jsulm well this was my answer
INKA01010100221.000000000000000000000000000000000000000000000000
I wanted 021 only the last three digits to get added@Vineela See the fix from @J-Hilk - for me it is working.
-
@J-Hilk , @jsulm well INKA010101001 this is my QString value i just want to add 001 to the last so that i get the final value INKA010101001001 like this.
@Vineela And what is the problem? You can append a string easily to another one...
-
@jsulm oh yes ive tried that i got INKA010101001\u0001 this
I've used this codeQString dd= store; dd.append(001);
-
@jsulm oh yes ive tried that i got INKA010101001\u0001 this
I've used this codeQString dd= store; dd.append(001);
//String concatenation QString a("123"); QString b("001"); int num =1; QString c = a + b == a.append(b) == a + QString::number(num).rightJustified(3,QChar('0'));
-
-
wrote on 19 Jan 2019, 05:23 last edited by
please mark the topic as solved
-
please mark the topic as solved
wrote on 21 Jan 2019, 04:39 last edited byThis post is deleted!
1/14