CodeDezk
CodeDezk

Reputation: 1260

Qt replace string between two string

I need to find the string between two string and replace it with a new string.

Here is the input string

QMainWindow#MainWindow{background-image: url(./Flocking_by_noombox.jpg);}

I need to identify the image name ./Flocking_by_noombox.jpg and replace with the new name without knowing what text inside url()

I think first I have to find the string between QMainWindow#MainWindow{background-image: url( and );} and replace it with new name.

How it's possible in Qt.

Upvotes: 0

Views: 796

Answers (1)

JLev
JLev

Reputation: 705

Quick and dirty solution, as @xander sugessted:

QString s = "QMainWindow#MainWindow{background-image: url(./Flocking_by_noombox.jpg);}";
int index = s.indexOf("url");
QString name = "someName";
QString after = "url(" + name + ");}";
QString replaced = s.mid(0,index) + after;

Upvotes: 1

Related Questions