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

(Added nim implementation)
Line 577:
* {SNOWMAN} x 1,
* {COMET} x 2
 
=={{header|Phix}}==
<lang Phix>function split_on_change(string in)
string out = ""
if length(in) then
integer prev = in[1]
for i=1 to length(in) do
integer ch = in[i]
if ch!=prev then
out &= ", "
prev = ch
end if
out &= ch
end for
end if
return out
end function
 
puts(1,split_on_change(`gHHH5YY++///\`))</lang>
{{Out}}
<pre>
g, HHH, 5, YY, ++, ///, \
</pre>
 
=={{header|PowerShell}}==
7,820

edits