2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
str
Usually regarded as&str
borrowing.str
andString
They are all utf-8 encoded.let mut s = String::new()
let data = "initial contents";
let s = data.to_string();
let s = "initial contents".to_string();
let s = String::from("initial contents")
.let mut s = String::from("foo");
s.push_str("bar");
// s is foobar
push_str
This method does not change the ownership of the string.
let mut s = String::from("lo");
s.push('l');
// s is lol
let s1 = String::from("Hello, ");
let s2 = String::from("world!");
let s3 = s1 + &s2; // note s1 has been moved here and can no longer be used
let s1 = String::from("tic");
let s2 = String::from("tac");
let s3 = String::from("toe");
let s = format!("{s1}-{s2}-{s3}");
Rust does not allow subscripting of individual characters in a string.
for c in "Зд".chars() {
println!("{c}");
}