Split a character string based on change of character: Difference between revisions
Content deleted Content added
→{{header|AppleScript}}: ( updated groupBy primitive – using a fold, rather than explicit recursion with span) |
→{{header|REXX}}: added zkl |
||
Line 265:
input string: gHHH5YY++///\
output string: g, HHH, 5, YY, ++, ///, \
</pre>
=={{header|zkl}}==
<lang zkl>fcn group(str){
C,out := str[0],Sink(C);
foreach c in (str[1,*]){ out.write(if(c==C) c else String(", ",C=c)) }
out.close();
}
group("gHHH5YY++///\\").println();</lang>
{{out}}
<pre>
g, HHH, 5, YY, ++, ///, \
</pre>
|