Load text from string

GroupDocs.Comparison allows to compare values from variables of string type. The following are the steps to compare text from variables:

  • Instantiate LoadOptions object and set LoadText property to true (this indicates that passed string contains text to be compared, not file path);
  • Instantiate Comparer object with source variable of string type and LoadOptions object created at previous step;
  • Call Add method and specify target variable of string type and LoadOptions object created at previous step;
  • Call Comparer method.
  • Call 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();
}

Can also be combined with different ways of passing documents (be it file path or stream), as shown in the following code example:

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);
    }
}

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSG and other documents with free to use online GroupDocs Comparison App.