History

Update token.ck

terry feng committed 3 years ago

Commit 91d181a1 parent 3c0df031 file · +33 −8Browse files

Showing the changes to examples/string (1 of 1 file). Show all

Unified · Split

examples/string/token.ck+33−8
@@ -1,14 +1,39 @@
1// the very hacked StringTokenizer1//----------------------------------------------------
2// name: StringTokenizer
3// desc: Break a string into tokens using a whitespace delimiter
4// Iterate through the tokens using next() + more()
5// or get(i) to get the i-th token
6//
7// author: terry feng
8//----------------------------------------------------
2 9
3// make one10StringTokenizer strtok;
4StringTokenizer tok;
5 11
6// set the string12// set the string
7tok.set( "tokenize me please!" );13strtok.set( "Tokenize me please!" );
8 14
9// iterate15// check how many tokens there are
10while( tok.more() )16<<< "tokens found:", strtok.size() >>>;
17
18// iterate through the tokens
19while( strtok.more() )
11{20{
12 // print21 // print current token
13 <<< tok.next(), "" >>>;22 <<< strtok.next(), "" >>>;
14}23}
24
25// reset the tokenizer
26strtok.reset();
27
28string foo;
29
30// get the first token and pass it to foo
31strtok.next( foo );
32<<< "first token:", foo >>>;
33
34// another way to get the first token
35<<< "first token:", strtok.get( 0 ) >>>;
36
37// get last token and pass it to foo
38strtok.get( strtok.size() - 1, foo );
39<<< "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