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:
import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.load.LoadOptions;
// ...
try (Comparer comparer = new Comparer("source text", new LoadOptions(true))) {
comparer.add("target text", new LoadOptions(true));
comparer.compare();
String result = comparer.getResultString();
}
The result is as follows:
The following code snippet shows how to combine the different ways of specifying documents:
import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.load.LoadOptions;
import java.io.FileInputStream;
import java.io.InputStream;
// ...
try (Comparer comparer = new Comparer(sourceInputStream)) {
comparer.add("target text", new LoadOptions(true));
comparer.compare();
String result = comparer.getResultString();
}
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.