gpt4 book ai didi

c# - 找到匹配的单词

转载 作者:太空宇宙 更新时间:2023-11-03 12:34:18 25 4
gpt4 key购买 nike

我有这段代码,我在字符串中搜索数组中的单词:

string wordlist = synonymslistbox.Items[q_index].ToString().Split(':')[0].Replace(',', ' ');

var pattern = new Regex(@"\W");

var qa = pattern.Split(first_sentence).Any(w => wordlist.Contains(w));

现在我想实现两件事,但我不知道该怎么做。

  1. 找出匹配的单词。此代码仅在找到时返回 true
  2. 当 first_sentences 是 i like my banjo 时,它不应该在 banjo 中找到字母 a 作为单词 a。当 a 在这样的句子中时,它应该只读为一个单词:i like a big beer at the end of the afternoon

最佳答案

  1. find out witch word was a match. this one just returns true if found.

代替任何,使用where:

var qa = pattern.Split(first_sentence).Where(w => wordlist.Contains(w));
  1. when first_sentences is "i like my banjo" then it should NOT find a in banjo as the word a. it should only read a as a single word when it is in a sentence like this below "i like a big beer at the end of the afternoon"

您的单词列表不应是字符串,而应是字符串列表或数组。确保它是一个包含“a”的列表。除此之外,您的代码将起作用

关于c# - 找到匹配的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41580807/

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