mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-28 14:59:18 +00:00
翻譯
This commit is contained in:
parent
52434a3438
commit
5717f3ba32
@ -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)
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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!("那不是一個我知道的顏色字。");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user