どうも、ちょげ(@chogetarou)です。
文字列(string)を全て大文字に変換する方法を紹介します。
方法

文字列(string)を全て大文字に変換するには、to_uppercase()を使います。
具体的には、「text.to_uppercase()
」のように、文字列からto_uppercase()を呼び出します。
//text=対象の文字列
let result: String = text.to_uppercase();
上記のto_uppercase()は、呼び出した文字列を全て大文字に変換した文字列(String型)を生成します。
使用例
fn main() {
let text: &str = "Hello,World";
let result: String = text.to_uppercase();
println!("{:?}", result);
}
出力:
"HELLO,WORLD"
コメント