Skip to content

Commit

Permalink
feat: string operations examples
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Klingenberg <fredrkl@gmail.com>
  • Loading branch information
fredrkl committed Nov 19, 2023
1 parent 132f29a commit 1856826
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions projects/collections/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,20 @@ fn main() {
_s.push_str(s2);
println!("{s2}");

let s1 = String::from("tic");
let s2 = String::from("tac");
let s3 = String::from("toe");

let s = s1 + "-" + &s2 + "-" + &s3;
println!("{s}");

// When operating on strings do not use indexing because it is not guaranteed to work with all languages as excepted
// This is the proper way to do it
for c in "Зд".chars() {
println!("{c}");
}

for b in "Зд".bytes() {
println!("{b}");
}
}

0 comments on commit 1856826

Please sign in to comment.