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

Content added Content deleted
(Add ed example)
(add SETL)
Line 2,665: Line 2,665:
g, HHH, 5, YY, ++, ///, \
g, HHH, 5, YY, ++, ///, \


=={{header|SETL}}==
<syntaxhighlight lang="setl">program split_a_character_string_based_on_change_of_character;
s := "gHHH5YY++///\\";
print(join_strings(", ", split_on_change(s)));

proc split_on_change(s);
parts := [];
loop while s /= "" do
parts with:= span(s, s(1));
end loop;
return parts;
end proc;

proc join_strings(s, parts);
if parts=[] then return ""; end if;
return parts(1) +/ [s + part : part in parts(2..)];
end proc;
end program;</syntaxhighlight>
{{out}}
<pre>g, HHH, 5, YY, ++, ///, \</pre>
=={{header|Sidef}}==
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">func group(str) {
<syntaxhighlight lang="ruby">func group(str) {