Load text from string
Leave feedback
On this page
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);
}
}
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Comparison for .NET examples, plugins, and showcase
- GroupDocs.Comparison for Java examples, plugins, and showcase
- Document Comparison for .NET MVC UI Example
- Document Comparison for .NET App WebForms UI Modern Example
- Document Comparison for Java App Dropwizard UI Modern Example
- Document Comparison for Java Spring UI Example
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.
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.