Struct TextSegment
A range of UTF-16 units: a grapheme cluster, a word or a run.
public readonly record struct TextSegment : IEquatable<TextSegment>
- Implements
- Inherited Members
Examples
// A family emoji is one grapheme cluster of eight UTF-16 units; "can't" is one word.
string text = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67 can't stop";
var graphemes = new List<TextSegment>();
foreach (TextSegment grapheme in TextSegmenter.Graphemes(text))
{
graphemes.Add(grapheme);
}
var words = new List<string>();
foreach (TextSegment word in TextSegmenter.Words(text))
{
words.Add(text.Substring(word.Start, word.Length));
}
bool inside = TextSegmenter.IsGraphemeBoundary(text, 2); // false: inside the family
Constructors
TextSegment(int, int)
A range of UTF-16 units: a grapheme cluster, a word or a run.
public TextSegment(int Start, int Length)
Parameters
Examples
// A family emoji is one grapheme cluster of eight UTF-16 units; "can't" is one word.
string text = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67 can't stop";
var graphemes = new List<TextSegment>();
foreach (TextSegment grapheme in TextSegmenter.Graphemes(text))
{
graphemes.Add(grapheme);
}
var words = new List<string>();
foreach (TextSegment word in TextSegmenter.Words(text))
{
words.Add(text.Substring(word.Start, word.Length));
}
bool inside = TextSegmenter.IsGraphemeBoundary(text, 2); // false: inside the family
Properties
End
Gets the index just past the segment.
public int End { get; }
Property Value
Length
The number of UTF-16 units.
public int Length { get; init; }
Property Value
Start
The index of the first UTF-16 unit.
public int Start { get; init; }