MST

星途 面试题库

面试题:Rust字符串中字符替换的实现

在Rust中,给定一个字符串 `s = "hello world"`,请编写代码将其中所有的 `'l'` 字符替换为 `'x'`,并返回新的字符串。需要注意Rust字符串中字符的处理方式。
50.0万 热度难度
编程语言Rust

知识考点

AI 面试

面试题答案

一键面试
fn main() {
    let s = "hello world";
    let new_s = s.replace('l', "x");
    println!("{}", new_s);
}