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 the passed string contains a text to be compared, not a 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 the 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 a string with the comparison result.

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

const loadOptions = new groupdocs.comparison.LoadOptions();
loadOptions.setLoadText(true);
const comparer = new groupdocs.comparison.Comparer("source text", loadOptions);
comparer.add("target text", loadOptions);
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:

const loadOptions = new groupdocs.comparison.LoadOptions();
loadOptions.setLoadText(true);
const comparer = new groupdocs.comparison.Comparer(sourceInputStream);
comparer.add("target text", loadOptions);
comparer.compare();
String result = comparer.getResultString();

On this page