Replace an element in a QString
Unsolved
General and Desktop
-
Hello,
i have following problem:
I saved in a QString an XMLStart.QString f;
QString f:
<class="go"> <number>2</number> <column>3</column> <row>4</column>
I want to change for example the value of row with 7 in this String by for example using replace or something like that.
f.replace();
How can i achive that ? Is that possible?
Regards
-
Hi
yes its possible if you are carefulhttps://doc.qt.io/qt-5/qstring.html#replace-5
f.replace("row>4", "row>7")
or anything that will not replace other strings. so the trick is to see if there is something you can find it with.
if there are multi that matches all will be changed.If not, then you have to parse the XML and do it more structured.
-
@mrjj thank you. And how it would look if i want to put a variable instead of 7 in replace? how would be syntax for that?
-
f.replace("row>4", QString("row>%1").arg(variable));
-
thank you @jsulm.