Skip to content

Commit 90e6f78

Browse files
feat: Strings
1 parent 4c4398e commit 90e6f78

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

rustlang_book/strings/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "strings"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

rustlang_book/strings/src/main.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
fn main() {
2+
// Creating a string
3+
// Using to_string()
4+
let mut _string = String::new();
5+
let data = "initial contents";
6+
_string = data.to_string();
7+
8+
drop(_string);
9+
// Using String::from()
10+
let mut _string = String::from("initial contents");
11+
drop(_string);
12+
13+
// Updating a String
14+
let mut _string = String::from("foo");
15+
let string_2 = "bar";
16+
17+
_string.push_str(string_2);
18+
drop(_string);
19+
20+
// Indexing into strings
21+
let _string = String::from("Hello World");
22+
23+
// Slicing strings
24+
let _world = &_string[6..];
25+
26+
// Iterating over String
27+
for character in _string.chars() {
28+
println!("{character}");
29+
}
30+
}

0 commit comments

Comments
 (0)