summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/utf8replace_rs.rs
blob: 717978aa319dcf612c490b2f066b2deda184dba1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

pub fn main() {
    let mut hello = String::from("hell😀 world");
    println!("{}", hello);
    
    hello.replace_range(
        hello
            .char_indices()
            .nth(4)
            .map(|(pos, ch)| (pos..pos + ch.len_utf8()))
            .unwrap(),
        "🐨",
    );
    println!("{}", hello);

    for c in hello.chars() { 
        print!("{},", c);
    }
}