Welcome!

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

Reply
Highlighted
Developer
Posts: 48
Registered: ‎03-27-2011
My Device: BlackBerry Z10
My Carrier: Telstra
Accepted Solution

String manipulation

I want to pass an HTTP request where the name has an embedded comma.

As an example, the following url is fixed as "HTTP://www.test.com/feed/rss.abc?q=good".

I want to insert the word hello followed by a comma (,) before the word good.

Starting at position 33, i am able to insert a parametre by using the following - :

 

QString chosenWord = "hello";

QString pathUrl = httpAddress;               

pathUrl.insert(33, chosenWord) + ",";

 

 

I obtain the following :- 

 =>>> pathUrl is HTTP://www.test.com/feed/rss.abc?q=good

 =>>> pathUrl is HTTP://www.test.com/feed/rss.abc?q=hellogood

I just can't get the comma(,) between hello and good! Tried numerous values after the plus (+) sign to no avail. Anyone to the rescue?

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: String manipulation

i don't see a '+' operator in the docs, only '+=', so maybe it is not working because you use it wrong.
i would suggest that you manipulate the insertion string first, then append it.

what was also helpful to me was understanding the arg method of QString which allows you to replace certain parts, for example:
QString("lalala%1").arg("la") would replace the '%1' with 'la'
(just in case, maybe it is helpful for you!)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 48
Registered: ‎03-27-2011
My Device: BlackBerry Z10
My Carrier: Telstra

Re: String manipulation

Thanks simon_hain. You were right in using the += operand, unfortunately it appended the ',' at the end of the string. I am now going thru QString documentation to see if I can find the solution. If you find a solution before I do, please let me know. Thanks.

Developer
Posts: 48
Registered: ‎03-27-2011
My Device: BlackBerry Z10
My Carrier: Telstra

Re: String manipulation

All solved! Used QString Public Functions replace and insert.