Can anybody help me for find next index of particular string ?
-
i have one string like below:
QString str = Ddhh (copy)(1).txt;
i have to each time increase the 1 by 1. means if its 1 then i have to make it 2. if its 2 then i have tom make it 3.
can anybody suggest me way to achieve this with example ?
-
i have one string like below:
QString str = Ddhh (copy)(1).txt;
i have to each time increase the 1 by 1. means if its 1 then i have to make it 2. if its 2 then i have tom make it 3.
can anybody suggest me way to achieve this with example ?
@Qt-embedded-developer
because I'm feeling festive!
Here's a very crude and unoptimised way:QString s{"Ddhh (copy)(1).txt"}; for(int i {10}, j{50}; i < j; i++) { auto indexStart = s.lastIndexOf(QRegularExpression("\\(.+?\\)")); auto indexEnd = s.indexOf(QRegularExpression("\\)"), indexStart+1); QString left = s.left(indexStart +1); QString right = s.right(s.size() - indexEnd); int copyCount = s.midRef(indexStart +1, indexEnd - indexStart -1).toInt(); s = left + QString::number(++copyCount) + right; qDebug() << s; }
-
@Qt-embedded-developer
because I'm feeling festive!
Here's a very crude and unoptimised way:QString s{"Ddhh (copy)(1).txt"}; for(int i {10}, j{50}; i < j; i++) { auto indexStart = s.lastIndexOf(QRegularExpression("\\(.+?\\)")); auto indexEnd = s.indexOf(QRegularExpression("\\)"), indexStart+1); QString left = s.left(indexStart +1); QString right = s.right(s.size() - indexEnd); int copyCount = s.midRef(indexStart +1, indexEnd - indexStart -1).toInt(); s = left + QString::number(++copyCount) + right; qDebug() << s; }
@J-Hilk Dear J-hilk. your code helped me but may i know the reason why you have taken for loop ?
-
@J-Hilk Dear J-hilk. your code helped me but may i know the reason why you have taken for loop ?
@Qt-embedded-developer as a, also very crude, Unit-Test. See if it works multiple times, and for multiple ranges of numbers