【发布时间】:2020-09-18 02:45:34
【问题描述】:
dictNum2 = {{"eins", 1}, {"zwei", 2}, {"drei", 3} ...};
foreach (KeyValuePair<string, int> dsa in dictNum2)
{
Regex regexTemp = new Regex(dsa.Key);
MatchCollection matchTemp = regexTemp.Matches(stringInput);
if ((stringInput.Contains(dsa.Key) && dsa.Value < 10))
{
var indexList = Regex.Matches(stringInput, dsa.Key).Cast<Match>().Select(m => m.Index).ToList();
indexList.AddRange(indexList);
for(int i = 1; i < indexList.Count; i++)
{
if(indexList[i] == indexList[i-1] + dsa.Key.Length)
{
inaRow++;
}
}
}
}
这个想法是:需要找到一个字符串中彼此跟随的单词的数量,该字符串包含在字典中。我有一段代码适用于“zweizweizwei”之类的东西,但输入可能是这样的字符串:
“zweihundertzweidreiundzwanzig”或“zweiunddreieins”
有办法解决吗?谢谢
【问题讨论】: