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"
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 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.