Load text from string
Leave feedback
On this page
GroupDocs.Comparison allows you to compare values from the string
type variables.
To compare text from variables, follow these steps:
- Instantiate the LoadOptions object. Set the LoadText property to
true
(this indicates that passed string contains text to be compared, not file path). - Instantiate the Comparer object. Specify the source variable of the
string
type and the LoadOptions object created in the previous step. - Call the Add method. Specify target variable of the
string
type and the LoadOptions object created in the previous step. - Call the Comparer method.
- Call the GetResultString method to get string with comparison result.
The following code snippet shows how to load values from variables:
using System;
using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
// ...
using (Comparer comparer = new Comparer("source text", new LoadOptions() { LoadText = true }))
{
comparer.Add("target text", new LoadOptions() { LoadText = true });
comparer.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 System;
using GroupDocs.Comparison;
using GroupDocs.Comparison.Options;
using System.IO;
// ...
using (Stream sourceStream = File.OpenRead("./source.docx"))
{
using (Comparer comparer = new Comparer(sourceStream))
{
comparer.Add("target text", new LoadOptions() { LoadText = true });
comparer.Compare();
string result = compare.GetResultString();
Console.WriteLine(result);
}
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.