terry fengUpdate token.ck91d181a3 years agoHistory
39 lines · 927 B · Text
RawDownload
//----------------------------------------------------// name: StringTokenizer// desc: Break a string into tokens using a whitespace delimiter//       Iterate through the tokens using next() + more() //       or get(i) to get the i-th token//// author: terry feng//---------------------------------------------------- StringTokenizer strtok; // set the stringstrtok.set( "Tokenize me please!" ); // check how many tokens there are<<< "tokens found:", strtok.size() >>>; // iterate through the tokenswhile( strtok.more() ){    // print current token    <<< strtok.next(), "" >>>;} // reset the tokenizerstrtok.reset(); string foo; // get the first token and pass it to foostrtok.next( foo );<<< "first token:", foo >>>; // another way to get the first token<<< "first token:", strtok.get( 0 ) >>>; // get last token and pass it to foostrtok.get( strtok.size() - 1, foo );<<< "last token:", foo >>>;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t