Tokenize a string: Difference between revisions

Content added Content deleted
(Add min)
No edit summary
Line 1,395:
To tokenize the string, we use the Search/Split String function to split the string by its first comma. Add the beginning (up to, but not including the comma) to the end of the array, remove the first comma from the rest of the string, and pass it back through the shift register to the loop's next iteration. This is repeated until the string is empty. Printing is a simple matter of concatenation.<br/>
{{VI solution|LabVIEW_Tokenize_a_string.png}}
 
=={{header|LDPL}}==
<lang ldpl>
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
</lang>
 
=={{header|LFE}}==