The SPLIT command

7 views
Skip to first unread message

Stuart Allen

unread,
Dec 9, 2011, 3:55:44 AM12/9/11
to jacl-discuss
Hi all

I'm working on a text JACL program for managing tasks (I really must
get back to using JACL to write Interactive Fiction one day...) and I
needed a way to parse dates. As a result I decided the best thing to
do was to add a relatively generic command for splitting a string into
substrings. The basic syntax is

split container source_text delimeter array

The basic idea is that it looks for occurrences of the string
"delimiter" in "source_text" and copies the text in between each
delimiter into array[0]...array[n]. The total number of matches is
stored in "container"

Here is a working example:

#!../bin/jacl

integer temp
integer index

string_array chunk 20

{+intro
split temp "This is,a test,of the,new split,command" "," "chunk"
write "CHUNKS = " temp "^"
set index = 0
repeat
write "chunk[index] = " chunk[index] "^"
set index + 1
until index = temp
terminate
}


Stuart

Stuart Allen

unread,
Dec 9, 2011, 4:00:04 AM12/9/11
to jacl-discuss
Erm, so THIS is a working example...

#!../bin/jacl

integer temp
integer chunknum

string_array chunk 20

{+intro
split temp "This is,a test,of the,new split,command" "," "chunk"
write "CHUNKS = " temp "^"

set chunknum = 0
repeat
write "chunk[chunknum] = " chunk[chunknum] "^"
set chunknum + 1
until chunknum = temp
terminate

Reply all
Reply to author
Forward
0 new messages