gpt4 book ai didi

string - 获取句子中单词的第一个字母

转载 作者:行者123 更新时间:2023-11-29 07:55:50 24 4
gpt4 key购买 nike

我如何从一个句子中获取第一个字母;示例:“Rust 是一种快速可靠的编程语言”应该返回输出 riafrpl

fn main() {
let string: &'static str = "Rust is a fast reliable programming language";
println!("First letters: {}", string);
}

最佳答案

let initials: String = string
.split(" ") // create an iterator, yielding words
.flat_map(|s| s.chars().nth(0)) // get the first char of each word
.collect(); // collect the result into a String

关于string - 获取句子中单词的第一个字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50330070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com