Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Replacing a substring in a string
Re: Replacing a substring in a string [message #480010 is a reply to message #479987] Thu, 21 March 2013 06:14 Go to previous messageGo to previous message
danpaul88 is currently offline  danpaul88
Messages: 5795
Registered: June 2004
Location: England
Karma:
General (5 Stars)
Depends on a few things. If you just want pointers to both strings and don't mind them staying in the same memory block as each other you can write over the first character of the strstr result with a null character and advance its position by <length of search string> to get the pointer to the second string, using the original pointer as the pointer to the first string. Repeat until there are no more matches as necessary, either acting on each bit of string one at a time or accumulating the pointers in a vector or other storage container (pre-allocate it to a decent size first to avoid reallocations mid-processing as much as possible).

That's just one way of doing it off the top of my head. It's destructive to the source string (you could copy it first if this is a problem) but it allows you to split a string into multiple substrings. This is equivilent to how strtok works.


http://steamsignature.com/card/1/76561197975867233.png

[Updated on: Thu, 21 March 2013 06:15]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Renhelp.net
Next Topic: C&C_Carriers *wip*
Goto Forum:
  


Current Time: Fri Nov 29 17:17:09 MST 2024

Total time taken to generate the page: 0.00767 seconds