Skip to main content
gamedev.net
🔒 Locked

std::string manipulation

Started by Laroche Dec 5, 2002 at 6:15 PM 2 replies 300+ views
Original Post
Laroche
Laroche
How would i scan a std::string for a certain character, and then copy from that character and on into a new string? Im asking because i''ve implemented RLE into my map saving routine, which stores repeats by tile.id, something like 5:42, and im trying to load it properly, and i need to check the strings to see if they contain : and then get the number out of it. Any help would be apprecitated
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
TravisWells
TravisWells
This looks like it would work:
size_type find(charT c, size_type pos = 0) const

So, this should work:

string temp;
int position=temp.find('':'',0);

Now position should contain the position of the first '':''. If you need the second just use the position as the second argument (where to start)
Fruny
Fruny
quote:
Original post by TravisWells
If you need the second just use the position as the second argument (where to start)


position + 1, and only if it was not equal to std::string::npos - which means the character wasn''t found.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

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

Sign in to reply to this topic.