Split a character string based on change of character
fn split(s: string) {
let len = strlen(s);
if len == 0 { return; }
let last = s[0];
for i in 0..len {
let curr = s[i];
if curr == last {
print "";
} else {
print ", ";
last = curr;
}
}
println "";
}
fn main() {
let s = "gHHH5YY++///\\";
split(s);
}
Output:
g, HHH, 5, YY, ++, ///, \
Attribution: This is a community solution for the Rosetta Code task Split a character string based on change of character in Zen C.
This article uses material from the Rosetta Code article Split a character string based on change of character, which is released under the GNU Free Documentation License 1.3. A list of the original authors can be found in the page history.