Tokenize a string: Difference between revisions

add language: Retro
No edit summary
(add language: Retro)
Line 1,028:
<pre>Original: Hello,How,Are,You,Today
Dotted: Hello.How.Are.You.Today.</pre>
 
 
=={{header|Retro}}==
<lang Retro>{{
: char ( -$ ) " " ;
: tokenize ( $-$$ )
@char ^strings'splitAtChar withLength 1- over + 0 swap ! tempString ;
: action ( $- )
keepString ^buffer'add ;
---reveal---
: split ( $cb- )
^buffer'set !char
char ^strings'append
[ tokenize action dup 1 <> ] while drop
^buffer'get drop ;
}}</lang>
 
This will suffice to split a string into an array of substrings. It is used like this:
 
<lang Retro>create strings 100 allot
"Hello,How,Are,You,Today" ', strings split</lang>
 
Since the buffer' vocabulary creates a zero-terminated buffer, we can display it using the each@ combinator and a simple quote:
 
<lang Retro>strings [ @ "%s." puts ] ^types'STRING each@</lang>
 
=={{header|REXX}}==
Anonymous user