gpt4 book ai didi

c# - 匹配词索引

转载 作者:太空宇宙 更新时间:2023-11-03 21:10:06 26 4
gpt4 key购买 nike

我必须知道匹配发生在哪个词中。

我认为可以使用下面的代码,但是给我索引并且里面没有单词计数器。

是否可以返回匹配发生在哪个单词之后的信息?

const string stringToTest = "Am Rusch";
const string patternToMatch = @"\bRusch*";

Regex regex = new Regex(patternToMatch, RegexOptions.Compiled);

MatchCollection matches = regex.Matches(stringToTest);

foreach (Match match in matches)
{
Console.WriteLine(match.Index);
}

字数应为 1,因为在第二个字中找到了匹配项。

最佳答案

string stringToTest用空格分开,就可以轻松找出匹配出现在哪个词中

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

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