Ask your own question, for FREE!
Computer Science 50 Online
OpenStudy (sanchez9457):

Okay so let's say i have a string passed on to me: a = "hello;theyarearbitrary;lengths; " i want just the words before ';'. i know i can use getline, but it would only get the first word and won't go through the rest, how would i get the rest of the words: theyarearbitrary;lengths; "?

OpenStudy (konradzuse):

I'm not sure what lang you are using, but there should be something called a "delimeter" in your case ';' is the delimeter.

OpenStudy (sanchez9457):

I'm using c++. I know i can use getline(string, 100, ';') but wouldn't that just get "hello" What if i wanted to also get "theyarearbitrary" and "lengths"?

OpenStudy (sanchez9457):

Doesn't getline just get the first thing before the delimeter then ignore the rest?

OpenStudy (konradzuse):

oic there are 3 words,. sorry.... you can go through the delimeter multiple times.

OpenStudy (sanchez9457):

How would you do that though? do you have to create a loop for getline?

OpenStudy (konradzuse):

not too sure how it works in C++, it should all be on the same line....

OpenStudy (rsmith6559):

Actually, you'd probably be better off using a scanner type class to tokenize the input string and then concatenate it back as you want.

OpenStudy (konradzuse):

oh yeah I forgot about tokenizers :). I saw the word once and checked it out briefly.... I don't do much with strings and stuff.... My dad loves them, but I don't use them much....

OpenStudy (sanchez9457):

Would it possible if one of you were to examplin it to me? i searched for it but i am lost.

OpenStudy (rsmith6559):

http://www.cplusplus.com/reference/cstring/strtok/ I thought the STL had a token class, guess not.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!