Skip to main content
GameDev.net gamedev.net
🔒 Locked

String manipulation

Started by Ruudje Oct 12, 2003 at 5:23 AM 5 replies 1k views
Original Post
Ruudje
Ruudje
Hey all ... this has got me stumped. At some point I cut off a part of a string by placing a "\0" in it. The problem is though, that at a later point I need to add another string to this string, which isnt possible, as it will be added AFTER the "\0", so effectively the string doesnt change... How can I do this so that I DO get the new part attached to it?
Stary
Stary
Assuming these are std::strings, use erase to cut the string instead.

mystring.erase(pos); 

Instead of
mystring[pos] = ''\0''; 


Then you can append a new string without a problem. The problem here is that a std::string is not a 0-delimited string by nature - you inserting ''\0'' in it doesn''t really change the string (it still has the same length).
Ruudje
Ruudje
Well unfortunately its an AnsiString
brassfish89
brassfish89
Copy the string starting at the position of ''\0'', then add one at the end of that string.

daerid
daerid
use strcat() ?
daerid@gmail.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.