Split a character string based on change of character: Difference between revisions
Content deleted Content added
added Tcl |
Implementation in Standard ML |
||
Line 540:
g, HHH, 5, YY, ++, ///, \
</pre>
=={{header|Standard ML}}==
<lang sml>(*
* Head-Tail implementation of grouping
*)
fun group' ac nil = [ac]
| group' nil (y::ys) = group' [y] ys
| group' (x::ac) (y::ys) = if x=y then group' (y::x::ac) ys else (x::ac) :: group' [y] ys
fun group xs = group' nil xs
fun groupString str = String.concatWith ", " (map implode (group (explode str)))</lang>
{{out}}
<pre>- groupString "gHHH5YY++///\\";
val it = "g, HHH, 5, YY, ++, ///, \\" : string</pre>
=={{header|Tcl}}==
|