gpt4 book ai didi

c# - 如何返回以特定字符开头和结尾的所有单词?

转载 作者:太空狗 更新时间:2023-10-30 00:16:28 26 4
gpt4 key购买 nike

我有如下单词列表:

List<string> words = new List<string>();
words.Add("abet");
words.Add("abbots"); //<---Return this
words.Add("abrupt");
words.Add("abduct");
words.Add("abnats"); //<--return this.
words.Add("acmatic");

我想返回所有以字母“a”开头且“t”作为第 5 个字母的 6 个字母的单词,结果应返回单词“abbots”和“abnats”。

var result = from w in words
where w.StartsWith("a") && //where ????

我需要添加什么子句才能满足第 5 个字母是“t”的要求?

最佳答案

var result = from w in words
where w.Length == 6 && w.StartsWith("a") && w[4] == 't'
select w;

关于c# - 如何返回以特定字符开头和结尾的所有单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7011549/

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