summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/strings/utf8replace_rs.rs
diff options
context:
space:
mode:
author_Tradam <[email protected]>2023-09-08 01:29:47 +0000
committerGitHub <[email protected]>2023-09-08 01:29:47 +0000
commit3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch)
treeafbe4b540967223911f7c5de36559b82154f02f3 /misc/examples/strings/utf8replace_rs.rs
parent0841165881871ee01b782129be681209aeed2423 (diff)
parent1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff)
downloadSTC-modified-modified.tar.gz
STC-modified-modified.zip
Merge branch 'stclib:master' into modifiedHEADmodified
Diffstat (limited to 'misc/examples/strings/utf8replace_rs.rs')
-rw-r--r--misc/examples/strings/utf8replace_rs.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/misc/examples/strings/utf8replace_rs.rs b/misc/examples/strings/utf8replace_rs.rs
new file mode 100644
index 00000000..8b163b4e
--- /dev/null
+++ b/misc/examples/strings/utf8replace_rs.rs
@@ -0,0 +1,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"));
+}