Tokenize a string: Difference between revisions
Content deleted Content added
→{{header|Python}}: Removed the one-liner as it does not store the intermediate list of words; and the last example as it does not work! |
Added Snobol4 |
||
Line 961: | Line 961: | ||
array := 'Hello,How,Are,You,Today' subStrings: $,. |
array := 'Hello,How,Are,You,Today' subStrings: $,. |
||
array inject: '' into: [:concatenation :string | concatenation, string, '.' ]</lang> |
array inject: '' into: [:concatenation :string | concatenation, string, '.' ]</lang> |
||
=={{header|SNOBOL4}}== |
|||
For this task, it's convenient to define Perl-style split( ) and join( ) functions. |
|||
<lang SNOBOL4> define('split(chs,str)i,j,t,w2') :(split_end) |
|||
split t = table() |
|||
sp1 str pos(0) (break(chs) | rem) $ t<i = i + 1> |
|||
+ span(chs) (break(chs) | '') . w2 = w2 :s(sp1) |
|||
* t<i> = differ(str,'') str ;* Uncomment for CSnobol |
|||
split = array(i) |
|||
sp2 split<j = j + 1> = t<j> :s(sp2)f(return) |
|||
split_end |
|||
define('join(ch,a)i,') :(join_end) |
|||
join join = join a<i = i + 1> |
|||
join = join ?a<i + 1> ch :s(join)f(return) |
|||
join_end |
|||
* # Test and display |
|||
output = join('.',split(',','Hello,How,Are,You,Today')) |
|||
end</lang> |
|||
Output: |
|||
<pre>Hello.How.Are.You.Today</pre> |
|||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |