Anonymous user
Split a character string based on change of character: Difference between revisions
Split a character string based on change of character (view source)
Revision as of 01:43, 21 January 2017
, 7 years agoAdded Ruby
(→{{header|Perl 6}}: typo) |
(Added Ruby) |
||
Line 382:
input string: gHHH5YY++///\
output string: g, HHH, 5, YY, ++, ///, \
</pre>
=={{header|Ruby}}==
<lang ruby>def split(str)
puts " input string: #{str}"
s = str.chars.chunk(&:itself).map{|_,a| a.join}.join(", ")
puts "output string: #{s}"
s
end
split("gHHH5YY++///\\")</lang>
{{out}}
<pre>
input string: gHHH5YY++///\
output string: g, HHH, 5, YY, ++, ///, \
</pre>
|