0

I want to make an application typing application which have two text boxes, one is source from where the user can see the text to write in the second text box. When the user submits the result then it will show the error in the type text by comparing with source text box text. I try with diff-match-patch but not able to get result I want.

enter image description here

I have developed the same with diff class in php. But now want in vb for desktop application.

using DiffMatchPatch;
using System;
using System.Collections.Generic;

public class hello {
  public static void Main(string[] args) {
    diff_match_patch dmp = new diff_match_patch();
    List<Diff> diff = dmp.diff_main("Hello World.", "Goodbye World.");
    // Result: [(-1, "Hell"), (1, "G"), (0, "o"), (1, "odbye"), (0, " World.")]
    dmp.diff_cleanupSemantic(diff);
    // Result: [(-1, "Hello"), (1, "Goodbye"), (0, " World.")]
    for (int i = 0; i < diff.Count; i++) {
      Console.WriteLine(diff[i]);
    }
  }
}
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • 1
    If you want a VB solution then why have you posted C# code? Also, *"not able to get result I want"* is just another way of saying *"it doesn't work"* and that's never adequate. You need to provide a FULL and CLEAR explanation. – jmcilhinney Aug 09 '19 at 06:43
  • [Here](https://stackoverflow.com/questions/24887238/how-to-compare-two-rich-text-box-contents-and-highlight-the-characters-that-are/24970638#24970638) is a working example with diff-match. – TaW Aug 09 '19 at 07:50
  • example in the link compare character by character but i want to compare word(Token) – Bar Sidhu Aug 29 '19 at 16:15

1 Answers1

0

you could do this :

string source = "Hello World.";
string input = "Goodbye World.";

for(int x=0; x < source.Length; x++)
{
    if(source[x] != input[x])
        Console.WriteLine($"{x}\t{source[x]}\t{input[x]}");
}

this would compare it character by character

if you want it to be compared word by word, then you could convert the string to list then do the comparison.

string source = "Hello World.";
string input = "Goodbye World.";

var sourceList = source.Split(' ').ToList(); 
var inputList = input.Split(' ').ToList();

for (int x = 0; x < inputList.Count; x++)
{
    if(sourceList[x] != inputList[x])
    {
        Console.WriteLine($"{x}\t{sourceList[x].ToString()}\t{inputList[x].ToString()}");
    }
}

The rest depends on how to handle these mismatched values. You might find libraries do that for you, but this is a basic idea.

iSR5
  • 3,274
  • 2
  • 14
  • 13