Rust 文字列の最後の文字を削除する
Rustで、文字列の最後の文字を削除するサンプルコードを記述してます。「pop()」を使用します。Rustのバージョンは1.65.0を使用してます。
環境
- OS windows11 home
- rustc 1.65.0
文字列の最後の文字を削除
文字列の最後の文字を削除するには「pop()」を使用します。
"文字列".pop();
実際に使用してみます。
fn main() {
let mut str: String = "abcde".to_string();
println!( "{:?}", str.pop() );
// Some('e')
println!( "{}", str );
// abcd
str = "あいうえお".to_string();
println!( "{:?}", str.pop() );
// Some('お')
println!( "{}", str );
// あいうえ
str = "😇😶😶".to_string();
println!( "{:?}", str.pop() );
// Some('😶')
println!( "{}", str );
// 😇😶
}
実行結果を見ると、削除されていることが確認できます。
-
前の記事
windows11 新しいフォルダを作成するショートカットキー 2022.12.03
-
次の記事
Vagrant プラグインをアップデートする 2022.12.03
コメントを書く