Tokenize a string: Difference between revisions
Content added Content deleted
mNo edit summary |
m (→{{header|REXX}}: added wording to a REXX section header, added a better fence for the output, added/changed whitespace and comments, used a template for the output section.) |
||
Line 2,387: | Line 2,387: | ||
===version 1=== |
===version 1=== |
||
This REXX version doesn't append a period to the last word in the list. |
This REXX version doesn't append a period to the last word in the list. |
||
<lang rexx>/*REXX program separates a string of |
<lang rexx>/*REXX program separates a string of comma─delimited words, and echoes them ──► terminal*/ |
||
original = 'Hello,How,Are,You,Today' /*some words separated by commas (,). */ |
|||
say 'input string |
say 'The input string:' original /*display original string ──► terminal.*/ |
||
new= |
new= original /*make a copy of the string. */ |
||
do #=1 until new=='' /*keep processing until NEW is empty.*/ |
|||
parse var new @.# ',' new /*parse words delineated by a comma (,)*/ |
|||
⚫ | |||
parse var new a.items ',' new /*parse words delinated by comma.*/ |
|||
say /* NEW is destructively parsed. [↑] */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{{out|output|text= when using the internal default input:}} |
|||
⚫ | |||
⚫ | |||
═════════ Words in the string ══════════ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
{{out}} |
|||
⚫ | |||
⚫ | |||
Words in the string: |
|||
Hello. |
Hello. |
||
How. |
How. |
||
Line 2,414: | Line 2,410: | ||
You. |
You. |
||
Today |
Today |
||
═════════════ End─of─list ══════════════ |
|||
End-of-list. |
|||
</pre> |
</pre> |
||
===version 2=== |
===version 2=== |
||
This REXX version won't work if any of the words have an embedded blank (or possible a tab character) in them, as in: |
|||
Hello,Betty Sue,How,Are,You,Today |
|||
<lang rexx>/*REXX program to separate a string of comma-delimited words and echo */ |
<lang rexx>/*REXX program to separate a string of comma-delimited words and echo */ |
||
sss='Hello,How,Are,You,Today' |
sss='Hello,How,Are,You,Today' |
||
Line 2,430: | Line 2,429: | ||
End |
End |
||
say 'End-of-list.'</lang> |
say 'End-of-list.'</lang> |
||
'''output''' is |
'''output''' is similar to REXX version 1. |
||
=={{header|Ring}}== |
=={{header|Ring}}== |