TextDiff Class
Computes the differences between two texts.
public static class TextDiffMethods
| Name | Description |
|---|---|
| ComputeDiff(string, string, TextDiffOptions?) | Computes the differences between oldText and newText. |
| ComputeHierarchyDiff(string, string, IReadOnlyList<TextChunker>, TextDiffOptions?) | Computes the differences between oldText and newText, refining each changed chunk with the next chunker in chunkers. |
ComputeDiff(string, string, TextDiffOptions?)
TextDiff.csComputes the differences between oldText and newText.
public static TextDiffResult ComputeDiff(string oldText, string newText, TextDiffOptions? options = null)Parameters
oldTextstring- The original text.
newTextstring- The modified text.
optionsTextDiffOptions?- The chunking and comparison options. Defaults to a line diff using
TextDiffAlgorithm.Myerswith no option ignored.
Returns
TextDiffResult The chunks of both texts in order, each tagged with what happened to it.
Exceptions
ArgumentNullExceptionoldTextornewTextisnull.
ComputeHierarchyDiff(string, string, IReadOnlyList<TextChunker>, TextDiffOptions?)
TextDiff.csComputes the differences between oldText and newText, refining each changed chunk with the next chunker in chunkers.
public static TextDiffHierarchyResult ComputeHierarchyDiff(string oldText, string newText, IReadOnlyList<TextChunker> chunkers, TextDiffOptions? options = null)Parameters
oldTextstring- The original text.
newTextstring- The modified text.
chunkersIReadOnlyList<TextChunker>- The chunking levels, coarsest first — for example
[TextChunker.Lines, TextChunker.Words]. At least two are required; useTextDiff.ComputeDifffor a single level.TextDiffOptions.Chunkeris not used by this overload. optionsTextDiffOptions?- The comparison options. Defaults to
TextDiffAlgorithm.Myerswith no option ignored.
Returns
TextDiffHierarchyResult The chunks produced by the first chunker, each of which may carry a finer diff of its own.
Exceptions
ArgumentNullExceptionoldText,newTextorchunkersisnull.ArgumentExceptionchunkersholds fewer than two chunkers, or one of them isnull.