Split a character string based on change of character: Difference between revisions

m
Line 667:
 
=={{header|REXX}}==
===version 1===
<lang rexx>/*REXX program splits a string based on change of character ───► a comma delimited list.*/
parse arg str . /*obtain optional arguments from the CL*/
Line 685 ⟶ 686:
output string: g, HHH, 5, YY, ++, ///, \
</pre>
===version 2===
<lang rexx>Parse Arg str . /*obtain optional arguments from the CL*/
If str=='' | str=="," Then str= 'gHHH5YY++///\' /*Not specified? Then use the default.*/
i=1
ol=''
Do Forever
j=verify(str,substr(str,i,1),'N',i,99) /* find first character that's different */
If j=0 Then Do /* End of strin reached */
ol=ol||substr(str,i) /* the final substring */
Leave
End
ol=ol||substr(str,i,j-i)', ' /* add substring and delimiter */
i=j
End
Say ol</lang>
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
 
=={{header|Ruby}}==
2,299

edits