MST

星途 面试题库

面试题:Rust字符串常用实用函数的基本应用

在Rust中,给定一个字符串`let s = "hello, world!"`. 使用`split`函数以逗号为分隔符将其分割,并将分割后的子字符串收集到一个`Vec<String>`中,然后打印该`Vec`。
29.3万 热度难度
编程语言Rust

知识考点

AI 面试

面试题答案

一键面试
fn main() {
    let s = "hello, world!";
    let parts: Vec<String> = s.split(',')
                           .map(|part| part.trim().to_string())
                           .collect();
    println!("{:?}", parts);
}