Load text from string

On this page

GroupDocs.Comparison allows you to compare values from the string type variables.

To compare text from variables, follow these steps:

  1. Instantiate the LoadOptions object. Set the LoadText property to true (this indicates that passed string contains text to be compared, not file path).
  2. Instantiate the Comparer object. Specify the source variable of the string type and the LoadOptions object created in the previous step.
  3. Call the Add method. Specify target variable of the string type and the LoadOptions object created in the previous step.
  4. Call the Comparer method.
  5. Call the GetResultString method to get string with comparison result.

The following code snippet shows how to load values from variables:

using (Comparer compare = new Comparer("source text", new LoadOptions() { LoadText = true }))
{
    compare.Add("target text", new LoadOptions() { LoadText = true });
    compare.Compare();
    string result = compare.GetResultString();
    Console.WriteLine("Result string: \n" + comparer.GetResultString());
}

The result is as follows:

The following code snippet shows how to combine the different ways of specifying documents:

using (Stream sourceStream = File.OpenRead("./source.docx"))
{
    using (Comparer compare = new Comparer(sourceStream))
    {
        compare.Add("target text", new LoadOptions() { LoadText = true });
        compare.Compare();
        string result = compare.GetResultString();
        Console.WriteLine(result);
    }
}

On this page