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 09:22, 11 January 2022
, 2 years ago→{{header|Rust}}
(Added solution for Action!) |
|||
Line 2,222:
output string: g, HHH, 5, YY, ++, ///, \
</pre>
===Alternate using IterTools===
<lang Rust>use itertools::Itertools;
pub fn split_text(s: &str) -> Vec<String> {
let mut r = Vec::new();
for (_, group) in &s.chars().into_iter().group_by(|e| *e) {
r.push(group.map(|e| e.to_string()).join(""));
}
r
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_splitting_text() {
assert_eq!(split_text("gHHH5YY++///\\"), vec!["g", "HHH", "5", "YY", "++", "///", "\\"]);
}
}
</lang>
=={{header|Scala}}==
|