Load text from string

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

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:

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();
}

On this page