diff --git a/src/references/strings.md b/src/references/strings.md index 9cfb9d35..e0a49a9a 100644 --- a/src/references/strings.md +++ b/src/references/strings.md @@ -13,6 +13,9 @@ We can now understand the two string types in Rust: - `&str` is a slice of UTF-8 encoded bytes, similar to `&[u8]`. - `String` is an owned, heap-allocated buffer of UTF-8 bytes. + + ```rust,editable fn main() { let s1: &str = "World"; @@ -23,7 +26,7 @@ fn main() { s2.push_str(s1); println!("s2: {s2}"); - let s3: &str = &s2[6..]; + let s3: &str = &s2[s2.len() - s1.len()..]; println!("s3: {s3}"); } ```