Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Developer
Posts: 46
Registered: ‎03-07-2014
My Device: BlackBerryZ10
My Carrier: BlackBerry

How to replace the new values in the string



I'm trying to replace the current string value with updated value but its not replacing with updated value. Its replacing only for the first time after its not replacing with any updated value.


// data contains webview content.I'm getting the updated value in //"currentPageInstanceId". I'm replacing with the updated values in //getJavaScript()

data = data.replace("</head>", "\n" + getJavaScript() + "\n" + "</head>");

QString MinervaLatest::getJavaScript()
	QString script;
	 qDebug() << "currentPageInstanceeeeeeeeId" << currentPageInstanceId;
	 qDebug() << "javaaaaaaaaa" << JAVASCRIPT;
	 script = JAVASCRIPT.replace("__PAGE_ID__"," " + currentPageInstanceId);
	 qDebug() << "replcae javaaaa" << JAVASCRIPT;

	//qDebug()<< "scripttttttt" << script;
	return script;



Thanks in Advance.

Posts: 170
Registered: ‎09-06-2010
My Device: None
My Carrier: None

Re: How to replace the new values in the string

You probably want to take a look at the reference for QString::replace() and make sure you're using it in the way you expected:




 QString myString = "Blah Blah XXX Blah Blah";
 myString.replace(QString("XXX"), QString("Wibble"));
// results in myString being changed to => "Blah Blah Wibble Blah Blah"

You seem to be using it as:


 QString myString = "Blah Blah XXX Blah Blah";
 QString myOtherString;
myOtherString = myString.replace(QString("XXX"), QString("Wibble"));
// results in myString being changed to => "Blah Blah Wibble Blah Blah"
// as well as myOtherString being set to => "Blah Blah Wibble Blah Blah"

Is this what you intended?


The reason QString::replace() returns a QString & is so that it's easy to chain things like:


 QString myString = "Blah Blah XXX Blah Blah YYY";

 myString.replace(QString("XXX"), QString("Wibble")).replace(QString("YYY"), QString("Frob"));
// results in myString being changed to => "Blah Blah Wibble Blah Blah Frob"