52 lines
1.7 KiB
Plaintext
52 lines
1.7 KiB
Plaintext
DATA:
|
|
explode/words is text vector
|
|
explode/index is number
|
|
explode/string is text
|
|
explode/length is number
|
|
explode/stringlength is number
|
|
explode/current-token is text
|
|
explode/char is text
|
|
explode/separator is text
|
|
i is number
|
|
|
|
PROCEDURE:
|
|
# Ask for a sentence
|
|
display "Enter a sentence: "
|
|
accept explode/string
|
|
|
|
# Declare explode Subprocedure
|
|
# Splits a text into a text vector by a certain delimiter
|
|
# Input parameters:
|
|
# - explode/string: the string to explode (destroyed)
|
|
# - explode/separator: the character used to separate the string (preserved)
|
|
# Output parameters:
|
|
# - explode/words: vector of splitted words
|
|
# - explode/length: length of explode/words
|
|
sub-procedure explode
|
|
join explode/string and explode/separator in explode/string
|
|
store length of explode/string in explode/stringlength
|
|
store 0 in explode/index
|
|
store 0 in explode/length
|
|
store "" in explode/current-token
|
|
while explode/index is less than explode/stringlength do
|
|
get character at explode/index from explode/string in explode/char
|
|
if explode/char is equal to explode/separator then
|
|
store explode/current-token in explode/words:explode/length
|
|
add explode/length and 1 in explode/length
|
|
store "" in explode/current-token
|
|
else
|
|
join explode/current-token and explode/char in explode/current-token
|
|
end if
|
|
add explode/index and 1 in explode/index
|
|
repeat
|
|
subtract 1 from explode/length in explode/length
|
|
end sub-procedure
|
|
|
|
# Separate the entered string
|
|
store " " in explode/separator
|
|
call sub-procedure explode
|
|
while i is less than or equal to explode/length do
|
|
display explode/words:i crlf
|
|
add 1 and i in i
|
|
repeat
|