add en/string.md

This commit is contained in:
sunface
2022-02-27 13:01:40 +08:00
parent e3bc581d03
commit f7099ea297
18 changed files with 367 additions and 47 deletions

View File

@ -1 +1,19 @@
# Iterator
```rust,editable
// (all the type annotations are superfluous)
// A reference to a string allocated in read only memory
let pangram: &'static str = "the quick brown fox jumps over the lazy dog";
println!("Pangram: {}", pangram);
// Iterate over words in reverse, no new string is allocated
println!("Words in reverse");
for word in pangram.split_whitespace().rev() {
println!("> {}", word);
}
// Copy chars into a vector, sort and remove duplicates
let mut chars: Vec<char> = pangram.chars().collect();
chars.sort();
chars.dedup();
```