mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 04:29:41 +00:00
add solutions for string.md
This commit is contained in:
@ -14,7 +14,7 @@ fn main() {
|
||||
```
|
||||
|
||||
|
||||
🌟🌟🌟 如果要使用 `str` 类型,只能配合 `Box`。 `&` 可以用来将 `Box<str>` 转换为 `&str` 类型
|
||||
🌟🌟 如果要使用 `str` 类型,只能配合 `Box`。 `&` 可以用来将 `Box<str>` 转换为 `&str` 类型
|
||||
|
||||
```rust,editable
|
||||
|
||||
@ -51,7 +51,7 @@ fn main() {
|
||||
// 修复所有错误,并且不要新增代码行
|
||||
fn main() {
|
||||
let s = String::from("hello");
|
||||
s.push(',');`
|
||||
s.push(',');
|
||||
s.push(" world");
|
||||
s += "!".to_string();
|
||||
|
||||
@ -79,7 +79,7 @@ fn main() {
|
||||
|
||||
```rust,editable
|
||||
|
||||
// 修复所有错误
|
||||
// 修复所有错误,不要删除任何一行代码
|
||||
fn main() {
|
||||
let s1 = String::from("hello,");
|
||||
let s2 = String::from("world!");
|
||||
|
@ -45,10 +45,12 @@ fn borrow_object(s: &String) {}
|
||||
fn main() {
|
||||
let mut s = String::from("hello, ");
|
||||
|
||||
borrow_object(&s)
|
||||
push_str(s)
|
||||
}
|
||||
|
||||
fn borrow_object(s: &mut String) {}
|
||||
fn push_str(s: &mut String) {
|
||||
s.push_str("world")
|
||||
}
|
||||
```
|
||||
|
||||
🌟🌟
|
||||
@ -151,7 +153,7 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
🌟🌟🌟
|
||||
🌟🌟
|
||||
```rust,editable
|
||||
|
||||
fn main() {
|
||||
|
Reference in New Issue
Block a user