Skip to main content
gamedev.net
🔒 Locked

Tokenize (???) A string

Started by GroZZleR Jul 30, 2002 at 11:16 PM 3 replies 300+ views
Original Post
GroZZleR
GroZZleR
Hey all, How can I loop through an array of characters, and than put it somewhere, based on a certain character. Like.. "The cat is fat" would become "The" "cat" "is" "fast", in an array or a list or something. I think thats called tokenizing, I could be wrong. Anyone know any pages with information on that such thing? Please no STL, I don''t get along with STL.
GroZZleR
GroZZleR
Oh! I also sort of want to write this myself, so I don''t want some big library or something.

The biggest problem I''m having, is trying to split it into different holders, so I can check against them.
Conner McCloud
Conner McCloud
I did something like that a while back...it wasn''t particuarly efficient, but it didn''t need to be fast. I just ran through the string once, collecting all the information I needed. I then ran through a second time and did all the manipulations. If you''re willing to use a linked list, you could do your task with just one run through the string. Start at the begining, and counting each character until you reach the char you''re looking for. Create a node on your list, with the data being a string as many characters as you need. Copy the important bit of the string, rinse, and repeat.

With that said, expect a few replies telling you to stop hating the STL. Of course, I''ve written my own library that I use, so I disagree to a certain extent.

CM
Silvanis
Silvanis
John Hattan created one in his diary. Look for the April 2nd entry...it''s only a dozen lines or so.

Topic Locked

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

Sign in to reply to this topic.