MST

星途 面试题库

面试题:Rust字符串查找与替换的基础实现

给定一个Rust字符串`str`,比如`let s = "hello world, hello rust";`,请编写代码实现将其中所有的`hello`替换为`hi`,并返回替换后的字符串。
13.3万 热度难度
编程语言Rust

知识考点

AI 面试

面试题答案

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