mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-03 07:48:41 +08:00
start off the start of strings
This commit is contained in:
parent
c9a21c8e5d
commit
65691eeeed
@ -3,16 +3,27 @@
|
||||
We've already talked about strings a bunch in chapter four, but let's take a
|
||||
more in-depth look at them now.
|
||||
|
||||
## creating
|
||||
## Creating
|
||||
|
||||
You can create an empty string with `new`:
|
||||
|
||||
```rust
|
||||
let s = String::new();
|
||||
```
|
||||
|
||||
new, String::from and .to_string()
|
||||
Often, you have some initial data that you'd like to start the string off with.
|
||||
For that, there's the `.to_string()` method:
|
||||
|
||||
## reading
|
||||
```rust
|
||||
let data = "initial contents";
|
||||
|
||||
let s = data.to_string();
|
||||
```
|
||||
|
||||
## Reading
|
||||
|
||||
slicing syntax, indexing
|
||||
|
||||
## updating
|
||||
## Updating
|
||||
|
||||
push_str, concatenation
|
||||
|
Loading…
Reference in New Issue
Block a user