どうも、ちょげ(@chogetarou)です。
文字列(string)の最後の文字を削除する方法を紹介します。
方法

文字列(string)の末尾の文字を削除するには、pop()を使います。
具体的には、「text.pop()
」のように、文字列からpop()を呼び出します。
//text=対象の文字列
text.pop();
上記のpop()は、呼び出した文字列(string)の末尾の文字を削除します。
使用例
fn main() {
let mut text: String = "Hello,World".to_string();
text.pop();
println!("{}", text);
}
出力:
Hello,Worl
コメント