TextEdit Struct

Describes the replacement of a range of characters of a text with another text, as the ApplyEdits methods apply it.

public readonly struct TextEdit : IEquatable<TextEdit>

Remarks

An edit whose TextEdit.Length is 0 is an insertion: it puts TextEdit.Text before the character at TextEdit.Start, or at the end of the text when TextEdit.Start is the length of the text. An edit whose TextEdit.Text is empty is a deletion.

A TextEdit accepts any value of TextEdit.Start and TextEdit.Length. The ApplyEdits methods check both against the text they are called on.

The default value is the insertion of an empty text at index 0, which changes no text.

See also

Implements

Constructors

NameDescription
TextEdit(int, int, string)Initializes a new instance of the TextEdit struct.

TextEdit(int, int, string)

Initializes a new instance of the TextEdit struct.

public TextEdit(int start, int length, string text)

Parameters

start int
The index, in the text, of the first character to replace.
length int
The number of characters to replace.
text string
The text that replaces the characters.

Properties

NameDescription
LengthGets the number of characters to replace.
StartGets the index of the first character to replace.
TextGets the text that replaces the characters.

Length

Gets the number of characters to replace.

public int Length { get; init; }

Property value

int The number of characters to replace, which is 0 for an insertion.

Start

Gets the index of the first character to replace.

public int Start { get; init; }

Property value

int An index in the text before any edit is applied to it.

Text

Gets the text that replaces the characters.

public string Text { get; init; }

Property value

string The text that replaces the characters, which is empty for a deletion. This property never returns null: the default value has an empty text.

Methods

NameDescription
Equals(TextEdit)Determines whether this edit and a specified edit are equal.
Equals(object?)Indicates whether this instance and a specified object are equal.
GetHashCode()Returns the hash code for this instance.

Equals overloads

Equals(TextEdit)

Determines whether this edit and a specified edit are equal.

public bool Equals(TextEdit other)
Parameters
other TextEdit
The edit to compare with this edit.
Returns

bool true if the two edits have the same TextEdit.Start, the same TextEdit.Length, and the same TextEdit.Text, compared by ordinal; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current instance.
Returns

bool true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int A 32-bit signed integer that is the hash code for this instance.

Operators

NameDescription
operator ==(TextEdit, TextEdit)Determines whether two specified TextEdit values are equal.
operator !=(TextEdit, TextEdit)Determines whether two specified TextEdit values are different.

operator ==(TextEdit, TextEdit)

Determines whether two specified TextEdit values are equal.

public static bool operator ==(TextEdit a, TextEdit b)

Parameters

a TextEdit
The first value to compare.
b TextEdit
The second value to compare.

Returns

bool true if a and b have the same TextEdit.Start, the same TextEdit.Length, and the same TextEdit.Text; otherwise, false.

operator !=(TextEdit, TextEdit)

Determines whether two specified TextEdit values are different.

public static bool operator !=(TextEdit a, TextEdit b)

Parameters

a TextEdit
The first value to compare.
b TextEdit
The second value to compare.

Returns

bool true if a and b differ in TextEdit.Start, in TextEdit.Length, or in TextEdit.Text; otherwise, false.