Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Really Simple C++ String Question

Status
Not open for further replies.

kjm2much

Technical User
Apr 21, 2005
1
US
Hello all,

I want to alter the string "science_rocket" so that is reads:

"rocket science"

Basically, switch the words and delete the underscore.
How can I do this?

Thanks,

Joe

 
assuming you are using CString

use .Find to get the position of the underscore
then use the .Right and .Left functions with the position of the underscore to break the string up
then use .Format to recombine the fragments in the order you want

"If it could have gone wrong earlier and it didn't, it ultimately would have been beneficial for it to have." : Murphy's Ultimate Corollary
 
If you want to go with ansi c functions you can use strtok function that will basically split your string, then just using the printf or sprintf you can switch places.

However snuv's will work better for most functionallity.
 
And if you are not using CString and you want to go with the ansi C++ functions you can use the string class and its find() and substr() methods.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top