[英]How do i find an incorrect words and their count in c#?
I like to sort the unmatched/wrong words from a given text for eg- string s1="let's play football" s2="let's paly fotbal and cricket"我喜欢从给定的文本中对不匹配/错误的单词进行排序,例如字符串 s1="let's play Football" s2="let's paly fotbal and cricket"
now I want the no.现在我想要没有。 of wrong as well as extra words in String-s2 like paly and fotbal,cricket and similarly the count of these wrong words. String-s2 中的错误以及额外的单词,如paly 和 fotbal、cricket以及类似的这些错误单词的计数。
string s1 = "let's play football";
string s2 = "let's paly fotbal and cricket";
if (s1 != s2)
{
var str1Parts = s1.Split(' ');
var str2Parts = s2.Split(' ');
var wrongOrExtraWords = str2Parts.Where(s => !str1Parts.Contains(s)).ToList();
Console.WriteLine("Wrong words: ({0})", wrongOrExtraWords.Count());
foreach (var str2 in wrongOrExtraWords)
{
Console.WriteLine(str2);
}
}
else
{
Console.WriteLine("Both strings are equal.");
}
string s1 = "let's play football";
string s2 = "let's paly fotbal and cricket";
string[] sArr1 = s1.Split(' ');
string[] sArr2 = s2.Split(' ');
int wrongCount = 0;
for (int i=0; i< sArr1.Length; i++)
{
if (sArr1[i] != sArr2[i]) //for different words
wrongCount++;
}
wrongCount += sArr2.Length - sArr1.Length; //for extra words
//wrongCount = 4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.