Tokenize a string: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Modula-3}}: Proper version, old version just used 5 for array bounds, this version dynamically allocates the required size.) |
||
Line 341: | Line 341: | ||
IMPORT IO, TextConv; |
IMPORT IO, TextConv; |
||
TYPE Texts = REF ARRAY OF TEXT; |
|||
VAR tokens: Texts; |
|||
string := "Hello,How,Are,You,Today"; |
|||
sep := SET OF CHAR {','}; |
sep := SET OF CHAR {','}; |
||
BEGIN |
BEGIN |
||
TextConv. |
tokens := NEW(Texts, TextConv.ExplodedSize(string, sep)); |
||
TextConv.Explode(string, tokens^, sep); |
|||
FOR i := FIRST(tokens) TO LAST(tokens) DO |
FOR i := FIRST(tokens^) TO LAST(tokens^) DO |
||
IO.Put(tokens[i] & "."); |
IO.Put(tokens[i] & "."); |
||
END; |
END; |