This commit is contained in:
TimLai666 2024-06-10 18:41:25 +08:00 committed by GitHub
parent 52434a3438
commit 5717f3ba32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 16 deletions

View File

@ -1,9 +1,8 @@
# Strings
# 字串
Rust has two string types, a string slice (`&str`) and an owned string (`String`).
We're not going to dictate when you should use which one, but we'll show you how
to identify and create them, as well as use them.
Rust 有兩種類型的字串:字串切片 (`&str`) 和 owned string (`String`)。
我們不會規定您應該何時使用哪一種,但我們會向您展示如何識別和創建它們,以及如何使用它們。
## Further information
## 更多資訊
- [Strings](https://doc.rust-lang.org/book/ch08-02-strings.html)
- [字串](https://doc.rust-lang.org/book/ch08-02-strings.html)

View File

@ -1,15 +1,14 @@
// strings1.rs
//
// Make me compile without changing the function signature!
// 使我在不改變函數簽名的情況下編譯!
//
// Execute `rustlings hint strings1` or use the `hint` watch subcommand for a
// hint.
// 執行 `rustlings hint strings1` 或使用 `hint` watch 子命令來獲取提示。
// I AM NOT DONE
fn main() {
let answer = current_favorite_color();
println!("My current favorite color is {}", answer);
println!("我現在最喜歡的顏色是 {}", answer);
}
fn current_favorite_color() -> String {

View File

@ -1,18 +1,17 @@
// strings2.rs
//
// Make me compile without changing the function signature!
// 使我在不改變函數簽名的情況下編譯!
//
// Execute `rustlings hint strings2` or use the `hint` watch subcommand for a
// hint.
// 執行 `rustlings hint strings2` 或使用 `hint` watch 子命令來獲取提示。
// I AM NOT DONE
fn main() {
let word = String::from("green"); // Try not changing this line :)
let word = String::from("green"); // 嘗試不要更改這行 :)
if is_a_color_word(word) {
println!("That is a color word I know!");
println!("那是一個我知道的顏色字!");
} else {
println!("That is not a color word I know.");
println!("那不是一個我知道的顏色字。");
}
}