0

I have a QString that contains:

<img class="openFile" data-id="../uploads/536b5621d91df1.76481105.png" src="../uploads/536b5621d91df1.76481105.png" />
iOS Simulator Screen shot 7 apr 2014 15.32.12.png

How can I extract whats inside src=""?

2 Answers 2

1

This answer should help you: https://stackoverflow.com/a/12432788/1221512

So your code should look like this:

QString data("<img class=\"openFile\" data-id=\"../uploads/536b5621d91df1.76481105.png\" src=\"../uploads/536b5621d91df1.76481105.png\" /> iOS Simulator Screen shot 7 apr 2014 15.32.12.png");
QString extractedData = data.section("src=\"",1).section("\"",0,0);

Also, may I suggest to use regular expression in combination with QString::filter()?

http://qt-project.org/doc/qt-4.8/qstringlist.html#filter

http://qt-project.org/doc/qt-5/QRegExp.html

Sign up to request clarification or add additional context in comments.

Comments

0

You can use QString::indexOf which returns the index position of the first occurrence of the string. After retrieving the indexes for the start and end, you can get the text by QString::mid :

int index1= str.indexOf ( "src=\"", 0);
index1+=5;

int index2 = str.indexOf("\"",index1);

QString src = str.mid(index1,index2-index1);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.