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 13:14, 2 June 2017
, 7 years ago→{{header|Rust}}
(Added Rust implmentation) |
|||
Line 748:
let mut result = Vec::<String>::new();
let mut last_mismatch = 0;
for i in
if chars
return chars[0..1].iter().map(|c| c ).collect();
}
if i > 0 && chars[i-1] != chars[i] {
let temp_result: String = chars[last_mismatch..i].iter().map(|c| c).collect();
result.push( temp_result );
Line 763 ⟶ 766:
fn main() {
let test_string = "g";
println!("input string: {}", test_string);
println!("output string: {}", splitter(test_string));
let test_string = "";
println!("input string: {}", test_string);
println!("output string: {}", splitter(test_string));
let test_string = "gHHH5YY++///\\";
println!("input string: {}", test_string);
println!("output string: {}", splitter(test_string));
}
{{out}}
<pre>
input string: g
output string: g
input string:
output string:
input string: gHHH5YY++///\
output string: g, HHH, 5, YY, ++, ///, \
</pre>
|