Chr*_*ium 19
使用String::push方法是最简单的方法:
let mut str = String::from("Hello World");
str.push('!');
Run Code Online (Sandbox Code Playgroud)
小智 8
您还可以使用format!:
fn main() {
let s = String::from("March");
// example 1
let s1 = format!("{}!", s);
// example 2
let s2 = format!("{}{}", s, '!');
// print
println!("{} {}", s1, s2);
}
Run Code Online (Sandbox Code Playgroud)
https://doc.rust-lang.org/std/macro.format.html
| 归档时间: |
|
| 查看次数: |
6559 次 |
| 最近记录: |