Rust 文字列の後ろに文字列を追加する
Rustで、文字列の後ろに文字列を追加するサンプルコードを記述してます。「push_str()」に追加したい文字列を指定することで可能です。Rustのバージョンは1.66.0を使用してます。
環境
- OS windows11 home
- rustc 1.66.0
文字列の後ろに文字列を追加
文字列の後ろに文字列を追加するには「push_str()」を使用します。
fn main() {
let mut str: String = "hello".to_string();
str.push_str(" world");
println!("{}", str);
}
実行結果
1文字の場合
1文字の場合は、「push()」も使用することが可能です。
fn main() {
let mut str: String = "hello".to_string();
str.push('!');
println!("{}", str);
}
実行結果
-
前の記事
GAS スプレッドシートのシートをコピーする 2023.12.06
-
次の記事
MariaDB 10進数を2進数に変換する 2023.12.06
コメントを書く