# OfficeDiff

Computes edit scripts between sequences: generic items with a comparer, or text split into lines, words or characters.

Class 

`OfficeIMO.Diff`

**Namespace**

`OfficeIMO.Diff`

**Assembly**

`OfficeIMO.Core`

**Source revision**

`ba882f6b0d07` with working tree changes

**Source**

[OfficeDiff.cs:20](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Diff/OfficeDiff.cs#L20)

**Modifiers**

static

Computes edit scripts between sequences: generic items with a comparer, or text split into lines, words or characters.

## Inheritance

- object
- OfficeDiff

## Remarks

Items are interned to integer ids first, so the comparer is called once per item rather than once per comparison. Every result is complete: when a work or time limit stops the alignment, the remaining regions are reported as whole deletions and insertions and [OfficeDiffResult<T>.LimitReached](/api/core/officeimo-diff-officediffresult/) is set.

Filter members 

Show inherited

## Methods

`public static OfficeDiffResult<OfficeTextToken> CompareCharacters(string? oldText, string? newText, OfficeDiffOptions? options = null, CancellationToken cancellationToken = default)` [#](#method-comparecharacters-string-string-officeimo-diff-officediffoptions-threading-cancellationtoken)

[OfficeDiff.cs:32](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Diff/OfficeDiff.cs#L32)

Compares two texts by user-perceived character (grapheme cluster).

Parameters

**oldText string? required**

**newText string? required**

**options OfficeIMO.Diff.OfficeDiffOptions? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`OfficeDiffResult<OfficeTextToken>`

`public static OfficeDiffResult<OfficeTextToken> CompareLines(string? oldText, string? newText, OfficeDiffOptions? options = null, CancellationToken cancellationToken = default)` [#](#method-comparelines-string-string-officeimo-diff-officediffoptions-threading-cancellationtoken)

[OfficeDiff.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Diff/OfficeDiff.cs#L24)

Compares two texts line by line. Line terminators are part of each line.

Parameters

**oldText string? required**

**newText string? required**

**options OfficeIMO.Diff.OfficeDiffOptions? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`OfficeDiffResult<OfficeTextToken>`

`public static OfficeDiffResult<OfficeTextToken> CompareTokens(IReadOnlyList<OfficeTextToken> oldTokens, IReadOnlyList<OfficeTextToken> newTokens, OfficeDiffOptions? options = null, CancellationToken cancellationToken = default)` [#](#member-ec71c9340b86245b562a2065)

[OfficeDiff.cs:37](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Diff/OfficeDiff.cs#L37)

Compares two token sequences produced by [OfficeTextTokenizer](/api/core/officeimo-diff-officetexttokenizer/) or by a caller, honouring the text settings in options.

Parameters

**oldTokens System.Collections.Generic.IReadOnlyList<OfficeIMO.Diff.OfficeTextToken> required**

**newTokens System.Collections.Generic.IReadOnlyList<OfficeIMO.Diff.OfficeTextToken> required**

**options OfficeIMO.Diff.OfficeDiffOptions? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`OfficeDiffResult<OfficeTextToken>`

`public static OfficeDiffResult<OfficeTextToken> CompareWords(string? oldText, string? newText, OfficeDiffOptions? options = null, CancellationToken cancellationToken = default)` [#](#method-comparewords-string-string-officeimo-diff-officediffoptions-threading-cancellationtoken)

[OfficeDiff.cs:28](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Diff/OfficeDiff.cs#L28)

Compares two texts word by word (see [OfficeTextTokenizer.Words](/api/core/officeimo-diff-officetexttokenizer/)).

Parameters

**oldText string? required**

**newText string? required**

**options OfficeIMO.Diff.OfficeDiffOptions? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`OfficeDiffResult<OfficeTextToken>`

`public static OfficeDiffResult<T?> Compare<T>(IReadOnlyList<T?> oldItems, IReadOnlyList<T?> newItems, IEqualityComparer<T?>? comparer = null, OfficeDiffOptions? options = null, CancellationToken cancellationToken = default)` [#](#method-compare-collections-generic-ireadonlylist-collections-generic-ireadonlylist-collections-generic-iequalitycomparer-officeimo-diff-officediffoptions-threading-cancellationtoken)

[OfficeDiff.cs:20](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Core/Diff/OfficeDiff.cs#L20)

Compares two sequences.

Type Parameters

**T**

Parameters

**oldItems System.Collections.Generic.IReadOnlyList<T?> required**

Old sequence.

**newItems System.Collections.Generic.IReadOnlyList<T?> required**

New sequence.

**comparer System.Collections.Generic.IEqualityComparer<T?>? = null optional**

Item comparer. Defaults to EqualityComparer<T>.Default.

**options OfficeIMO.Diff.OfficeDiffOptions? = null optional**

Diff settings.

**cancellationToken System.Threading.CancellationToken = default optional**

Cancels the alignment.

Returns

`OfficeDiffResult<T?>`

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

<!-- PowerForge markdown artifact sha256:C111977730EBE4D9FC8413947FE736C6BC26A28C4C4555064DFB77DED67C21A7 -->
