Jump to content

Tokenize a string: Difference between revisions

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.
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:
===version 1===
This REXX version doesn't append a period to the last word in the list.
<lang rexx>/*REXX program separates a string of comma-delimitedcomma─delimited words, and echoes. them ──► terminal*/
sssoriginal = 'Hello,How,Are,You,Today' /*some words seperatedseparated by commas (,). */
say 'The input string =:' sss original /*display the original string. ──► terminal.*/
new=sss original /*make a copy of the string. */
do #=1 until new=='' /*keep [↓]processing until string NEW is destroyedempty. */
do items=1 until new=='' parse var new @.# ',' new /*keepparse goingwords untildelineated by NEWa iscomma empty.(,)*/
end /*j#*/ /* [↑] don'tthe appendnew "."array ifis lastnamed @. */
parse var new a.items ',' new /*parse words delinated by comma.*/
say end /*items*/ /* [↑] the array is named A /* NEW is destructively parsed. [↑] */
say; say center(' Words in the string: ', 40, "═") /*display a nice header for the list. */
do j=1 for items# /*now, display all the words. (one per line),*/
say a@.j || left('.', j\==items#) /*maybe append a period (.) to word,a maybeword. */
end /*j*/ /*stick a[↑] fork indon't it,append we'rea doneperiod if last. */</lang>
say 'End-of-list.center(' End─of─list ', 40, "═") /*display a (EOL) trailer for the list.*/</lang>
{{out|output|text=&nbsp; when using the internal default input:}}
<pre>
The input string =: Hello,How,Are,You,Today
 
═════════ Words in the string ══════════
say; say 'Words in the string:' /*display a header for the list. */
 
do j=1 for items /*now, display all the words. */
say a.j || left('.', j\==items) /*append period to word, maybe. */
end /*j*/ /* [↑] don't append "." if last.*/
 
say 'End-of-list.' /*display a trailer for the list.*/
/*stick a fork in it, we're done.*/</lang>
{{out}}
<pre>
input string = Hello,How,Are,You,Today
Words in the string:
Hello.
How.
Line 2,414 ⟶ 2,410:
You.
Today
═════════════ End─of─list ══════════════
End-of-list.
</pre>
 
===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 */
sss='Hello,How,Are,You,Today'
Line 2,430 ⟶ 2,429:
End
say 'End-of-list.'</lang>
'''output''' is identicalsimilar to REXX version 1.
 
=={{header|Ring}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.