0

In my application, I have two strings and I need to display missing words that count, Inserting words that count and modified words that count between them. For example:

  string variable1="When you are writing server code you can never be sure what the IP address you see is refereeing to.In fact some users like it this way.";
  string variable2="when are wrting server code yu cannn never be sure **Demo** what the address you is to.In fact **Demo1** some users like it this way";

The result should be:

  Missing Words: you, see ,IP
  Missing Words count: 3

  Inserted: Demo, Demo1 
  Inserted Words count: 2

  Modified words : wrting,yu ,cannn ,refering
  Modified words count :4

I tried this but it not display properly in Modified Words

string variable1="When you are writing server code you can never be sure what the IP address you see is refereeing to.In fact some users like it this way.";
   string variable2="when are wrting server code yu cannn never be sure **Demo** what the IP address you see is to.In fact **Demo1** some users like it this way";

     //Missing Word Count    
     var result = variable1.Split(new char[] { ' ' }).Except(variable2.Split(new char[] { ' ' })).ToArray();
     count = result.Length;
     Label2.Text += "Missing Word Count: " + count.ToString() + "<br/><br/>";
     for (int i = 0; i < count; i++)
     {
       Label1.Text += "Missing Word: " + result[i].ToString() + "<br/><br/>";
     }


     //Insert Word
     var result1 = variable2.Split(new char[] { ' ' }).Except(variable1.Split(new char[] { ' ' })).ToArray();
     count = 0;
     count = result1.Length;
     for (int i = 0; i < count; i++)
     {
         Label3.Text += "Insert Word: " + result1[i].ToString() + "<br/><br/>";

     }
     Label4.Text += "Insert Word Count: " + count.ToString() + "<br/><br/>";    

     //Modifide Words
     string[] tempArr1 = variable1.Split(' ');  
     string[] tempArr2 = variable2.Split(' ');  
     int counter = 0;  

     for (int i = 0; i < tempArr1.Length; i++)  
     {  
         if (tempArr1[i] != tempArr2[i])  
         {  
            lblwords.text=tempArr1[i] + ", "+ tempArr2[i];  
             counter++;  
         }  
     } 

Can anyone help me to how to do this.

Thank you

  • 2
    try this http://stackoverflow.com/questions/24887238/how-to-compare-two-rich-text-box-contents-and-highlight-the-characters-that-are – Dgan Aug 24 '16 at 12:33
  • i need to display like this modified words : wrting,yu ,cannn ,refering modified words count :4. –  Aug 24 '16 at 12:45
  • logically you should have modified variable1-missingwords+insertedwords and compare with variable2, then you can determine the difference/modified ones. – kurakura88 Aug 25 '16 at 11:01
  • How can you tell the difference between a modified word and a deleted and then added word? – Enigmativity Aug 25 '16 at 11:13

1 Answers1

1

You can use Linq to achieve this

string s1 = "When you are writing server code you can never be sure what the IP address you see is refereeing to.In fact some users like it this way.";
string s2 = "are wrting server code yu cannn never be sure what the IP address you see is to.In fact some users like it this way.";
var list = s2.Split(' ').Where(x => (!s1.Split(' ').Contains(x))).ToList();

int count = list.Count;
foreach (var item in list)
{
 //your code
}
Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40
  • Hello Leopard. Thanks for your reply. i updated my Question. Here in my S2 i have Demo and Demo1 words, these words are not in S1. here i no need to display Demo and demo1 words,because those are not in s1. here what i want is, just i want to display words which are in S1 and that same words in s2 with spell mistakes. –  Aug 24 '16 at 13:49
  • @User107 This is you who can figure out that it is a spelling mistake, your program can't. The word `Demo` and `cannn` both are unknown words as compared to `s1`. All words must be in sequence to find out spelling mistakes. – Shaharyar Aug 25 '16 at 04:55
  • Hi, Shaharyar can you see once i updated my code. My requirement is need to display missing words,inserted words and modified words between two large strings(documents). i am getting missing and inserted words but i didn't get modified words i am trying this can you please help me it's very urgent requirement. –  Aug 25 '16 at 06:03