From 23bb6e2a9c94d36d7a6a12ece578e190ce59261d Mon Sep 17 00:00:00 2001 From: chenxuuu Date: Tue, 11 Jan 2022 10:03:48 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=94=B9=E5=9B=9E=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E4=B8=8D=E4=BA=86=E7=9A=84=E5=8E=9F=E6=A0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- book/contents/basic/compound-type/string-slice.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/contents/basic/compound-type/string-slice.md b/book/contents/basic/compound-type/string-slice.md index 4ddfb3b8..27162115 100644 --- a/book/contents/basic/compound-type/string-slice.md +++ b/book/contents/basic/compound-type/string-slice.md @@ -88,7 +88,7 @@ let slice = &s[..]; > println!("{}",a); >``` >因为我们只取`s`字符串的前两个字节,但是一个中文占用三个字节,因此没有落在边界处,也就是连`中`字都取不完整,此时程序会直接崩溃退出,如果改成`&a[0..3]`,则可以正常通过编译. -> 因此,当你需要对字符串做切片索引操作时,需要格外小心这一点, 关于该如何操作utf8字符串,参见[这里](#操作utf8字符串) +> 因此,当你需要对字符串做切片索引操作时,需要格外小心这一点, 关于该如何操作UTF8字符串,参见[这里](#操作UTF8字符串) 字符串切片的类型标识是`&str`,因此我们可以这样声明一个函数,输入`String`类型,返回它的切片: `fn first_word(s: &String) -> &str `.