41 lines
919 B
Plaintext
41 lines
919 B
Plaintext
include "cowgol.coh";
|
|
include "strings.coh";
|
|
|
|
# Tokenize a string. Note: the string is modified in place.
|
|
sub tokenize(sep: uint8, str: [uint8], out: [[uint8]]): (length: intptr) is
|
|
length := 0;
|
|
loop
|
|
[out] := str;
|
|
out := @next out;
|
|
length := length + 1;
|
|
while [str] != 0 and [str] != sep loop
|
|
str := @next str;
|
|
end loop;
|
|
if [str] == sep then
|
|
[str] := 0;
|
|
str := @next str;
|
|
else
|
|
break;
|
|
end if;
|
|
end loop;
|
|
end sub;
|
|
|
|
# The string
|
|
var string: [uint8] := "Hello,How,Are,You,Today";
|
|
|
|
# Make a mutable copy
|
|
var buf: uint8[64];
|
|
CopyString(string, &buf[0]);
|
|
|
|
# Tokenize the copy
|
|
var parts: [uint8][64];
|
|
var length := tokenize(',', &buf[0], &parts[0]) as @indexof parts;
|
|
|
|
# Print each string
|
|
var i: @indexof parts := 0;
|
|
while i < length loop
|
|
print(parts[i]);
|
|
print(".\n");
|
|
i := i + 1;
|
|
end loop;
|