diff options
Diffstat (limited to 'misc/examples/utf8replace_rs.rs')
| -rw-r--r-- | misc/examples/utf8replace_rs.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/misc/examples/utf8replace_rs.rs b/misc/examples/utf8replace_rs.rs index 717978aa..8b163b4e 100644 --- a/misc/examples/utf8replace_rs.rs +++ b/misc/examples/utf8replace_rs.rs @@ -1,12 +1,12 @@ - pub fn main() { - let mut hello = String::from("hell😀 world"); + 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(4) + .nth(7) .map(|(pos, ch)| (pos..pos + ch.len_utf8())) .unwrap(), "🐨", @@ -16,4 +16,7 @@ pub fn main() { 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")); } |
