t_wの輪郭

Rust文字列コレクション

String

2022/2/18 12:34:00

Rustの文字列オブジェクト
文字のコレクション

linesto_lowercasecontentsRustのStringを走査StringはVec<u8>のラッパ+演算子による文字列の結合+演算子によるStringとu32の結合(無理)+演算子によるStringとStringの結合format演算子またはformatマクロで連結push_strRustの文字列操作to_string()String::new()String::fromStringの難しさclone文字列リテラルからString型を生成

lines

2022/2/23 23:56:00

文字列を行ごとに繰り返すメソッド

let s = String::from("\
Rust:
safe, fast, productive.
Pick three.");
for line in s.lines() {
    println!("{}", line);
}

to_lowercase

2022/2/23 23:55:00

文字列を小文字にするメソッド

assert_eq!("Rust".to_lowercase(), "rust");
assert_eq!(String::from("Rust").to_lowercase(), String::from("rust"));

contents

2022/2/23 23:37:00

文字列にクエリ文字列を含むか確認するメソッド

let s = String::from("safe, fast, productive.");
println!("{}", s.contains("duct"));   //true
let s = "safe, fast, productive.";
println!("{}", s.contains("duct"));   //true

RustのStringを走査

2022/2/19 7:53:00
fn main() {
    let s = String::from("こんにちは世界");
    for b in s.chars() {
        println!("{}", b);
    }
}
こ
ん
に
ち
は
世
界

String&strの結合

fn main() {
    let s1 = String::from("Hello, ");
    let s2:&str = "world!";
    let s3 = s1 + &s2;      // s1はs3へ所有権が移動し、使用できなくなる
    println!("{}", s3);     // Hello, world!
}