Skip to content

Instantly share code, notes, and snippets.

@LeoBorai
Created October 17, 2020 05:14
Show Gist options
  • Save LeoBorai/7712dcb7437282aac0020b9107aeeef8 to your computer and use it in GitHub Desktop.
Save LeoBorai/7712dcb7437282aac0020b9107aeeef8 to your computer and use it in GitHub Desktop.
Rust - Split string slice in chunks
use std::str;
fn main() {
let subs = "‌​‌​‌​​‌​‌".as_bytes()
.chunks(7)
.map(str::from_utf8)
.collect::<Result<Vec<&str>, _>>()
.unwrap();
println!("{:?}", subs);
}
// >> ["&#8204;", "&#8203;", "&#8204;", "&#8203;", "&#8204;", "&#8203;", "&#8203;", "&#8204;", "&#8203;", "&#8204;"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment