How to format QString to remove % and & symbols for URL requests
-
I am using QWebView to display some html content, I have created one html file which launches some adobe flash content.
inside the html code for flash there is a src attribute which is nothing but a URL for the flash video,
which is having some % and & signs.
Adobe flash player plugin 10.3 and above does not take any % and & sign in the URL string.
So any idea how can I format my QString, which has HTML code , so that it will remove % and & signs and will replace these with some appropriate char set. Below mention is my html code that I stored in QString.@<html><body topmargin="0" leftmargin="0"><embed type="application/x-shockwave-flash" src="http://c.brightcove.com/services/viewer/federated_f9?&width=640&height=360&flashID=si_brightcove_experience&bgcolor=#000000&playerID=836271999001&playerKey=AQ~~,AAAAAGLxMrc~,SBQ2diQT3MIL51Crxxrcp2NU67P7DVl1&isVid=true&isUI=true&wmode=transparent&dynamicStreaming=true&@videoPlayer=1719922980001&autoStart=&debuggerID=&startTime=1342613597675" width="100%" height="100%" seamlesstabbing="false" class="BrightcoveExperience" id="si_brightcove_experience" data="http://c.brightcove.com/services/viewer/federated_f9?&width=640&height=360&flashID=si_brightcove_experience&bgcolor=#000000&playerID=836271999001&playerKey=AQ~~,AAAAAGLxMrc~,SBQ2diQT3MIL51Crxxrcp2NU67P7DVl1&isVid=true&isUI=true&wmode=transparent&dynamicStreaming=true&@videoPlayer=1719922980001&autoStart=&debuggerID=&startTime=1342613597675" type="application/x-shockwave-flash" PARAM="" allowScriptAccess="always" allowFullScreen="true" seamlessTabbing="false" swliveconnect="0" wmode="transparent" quality="high" bgcolor="#000000"></body></html>@
-
C++ Native
@
std::string s = SOME_STR;
std::replace( s.begin(), s.end(), '%', ''); // replace all '%' within 'empty symbol'
std::replace( s.begin(), s.end(), '&', ''); // replace all '&' within 'empty symbol'
@in qt :
@
QString s = "%%%text text text text text text text text&&&&text texttext text&&&&";
s.replace("%",""); // replace all '%' within 'empty symbol'
s.replace("&",""); // replace all '&' within 'empty symbol'
@ -
Another example:
..the method:
@void MyClass::replaceCharacter(QString &string, const char illegalCharacters[], const int &illegalCharactersSize, const char &characterToReplace) {for(int index(0); index < illegalCharactersSize; ++index) { string.replace(illegalCharacters[index], characterToReplace); }// for
}// replaceCharacter@
...the call:
@QString url = "This%is&a@test.";char illegalCharacters[4] = { '%', '&', '=', '@' };
int illegalCharactersSize = sizeof(illegalCharacters);
MyClass myclass;
myclass.replaceCharacter(url, illegalCharacters, illegalCharactersSize, '_');@
-
No Guyz you people misunderstood my requirements.
I am looking to format my QString in to a format which will be aligned to url char format. -
So, you're basically needing to parse, unencode, and simplify a URL?
If so, look at the QUrl documentation. It has some methods which may be helpful for you. "fromPercentEncoding":/doc/qt-4.8/qurl.html#fromPercentEncoding might be a good start. "path":/doc/qt-4.8/qurl.html#pathx and the queryItem methods might also be helpful as well.
(You'd have to manually pull out the URLs from the XML, of course, to process them.)