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

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

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:

try (Comparer comparer = new Comparer(sourceInputStream)) {
    comparer.add("target text", new LoadOptions(true));
    comparer.compare();
    String result = comparer.getResultString();
}

On this page