【Rust】連続した文字列を1個にする。
TL;DR
fn main() { println!("{}", space_replacer("hello world dayo e?".to_string().as_mut_str())); } fn space_replacer(src: &mut str) -> String { let dst = &mut src.replace(" ", " "); match dst.find(" ") { Some(_) => { space_replacer(dst) }, None => dst.to_string(), } } // => hello world dayo e?