blob: 8b163b4eb37185c345f2d6d04174db73b425c62c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
pub fn main() {
let mut hello = String::from("hell😀 w😀rld");
println!("{}", hello);
/* replace second smiley at utf8 codepoint pos 7 */
hello.replace_range(
hello
.char_indices()
.nth(7)
.map(|(pos, ch)| (pos..pos + ch.len_utf8()))
.unwrap(),
"🐨",
);
println!("{}", hello);
for c in hello.chars() {
print!("{},", c);
}
let str = "If you find the time, you will find the winner";
println!("\n{}", str.replace("find", "match"));
}
|