---
title: "Find Unicode sentence boundaries in C#"
url: https://recursiveai.org/onefont/cookbook/find-unicode-sentence-boundaries/
description: "Sentence segmentation finds sentence-sized ranges without removing punctuation or trailing spaces. Runnable C# example with onefont."
version: "1.4.0"
---

# Find Unicode sentence boundaries in C#

**onefont** is a free, open-source font and text-shaping library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneFont) · [GitHub](https://github.com/recursive-ai-oss/onefont-csharp) · [Docs](https://recursiveai.org/onefont/docs/) · [Download example (.zip)](https://recursiveai.org/onefont/cookbook/find-unicode-sentence-boundaries/find-unicode-sentence-boundaries.zip)

Sentence segmentation finds sentence-sized ranges without removing punctuation or trailing spaces.

```shell
dotnet add package RecursiveAI.OneFont
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneFont;

int[] cuts = TextSegmentation
    .GetSentenceBoundaries(
        "Hi. Yo! It is 3.5 ok.");
Console.WriteLine(string.Join(", ", cuts));
```

Unzip [the example](https://recursiveai.org/onefont/cookbook/find-unicode-sentence-boundaries/find-unicode-sentence-boundaries.zip), then `dotnet run`.

Prints:

```text
0, 4, 8, 21
```

These are UTF-16 sentence start offsets; the last offset is the text length.

`3.5` stays in one sentence, and abbreviations such as “Dr.” aren’t special-cased: these are the default rules, with no abbreviation list.

## The full program

All input text is in the program; no font file is needed.

```csharp
using OneFont;

string text = "Hi. Yo! It is 3.5 ok.";
int[] cuts = TextSegmentation
    .GetSentenceBoundaries(text);
Console.WriteLine(string.Join(", ", cuts));
for (int i = 0; i < cuts.Length - 1; i++)
    Console.WriteLine(
        $"[{text[cuts[i]..cuts[i + 1]]}]");
```

`dotnet run` prints:

```text
0, 4, 8, 21
[Hi. ]
[Yo! ]
[It is 3.5 ok.]
```

Empty text returns `[0]`.

## Variations

Mark each boundary in a caller-owned byte buffer. A `FillSentenceStarts` buffer shorter than the text plus one throws `ArgumentException`:

```csharp
using OneFont;

string text = "Hi. Yo! It is 3.5 ok.";
byte[] starts = new byte[text.Length + 1];
TextSegmentation.FillSentenceStarts(text, starts);
for (int i = 0; i < starts.Length; i++)
    if (starts[i] == 1)
        Console.WriteLine(i);
```

```text
0
4
8
21
```

## Related recipes

[Find Unicode word boundaries](https://recursiveai.org/onefont/cookbook/find-unicode-word-boundaries/)

[Find Unicode grapheme boundaries](https://recursiveai.org/onefont/cookbook/find-unicode-grapheme-boundaries/)

---

## The short answer

Call `TextSegmentation.GetSentenceBoundaries(text)` and slice between consecutive UTF-16 indexes. The returned array includes the input’s end offset. onefont uses the default Unicode 17 sentence rules from [UAX #29](https://www.unicode.org/reports/tr29/), without tailoring or an abbreviation list.

This is rule-based segmentation, not a language model classifying sentences. Use it when you need reproducible sentence-sized spans with their original offsets, such as text selection or sentence-by-sentence processing.

## How do you split text into sentences in C#?

The full program preserves punctuation and trailing whitespace. Brackets in the output make that whitespace visible: `[Hi. ]` contains a space before its closing bracket. They are display delimiters added by the sample, not characters in the input.

The array `0, 4, 8, 21` closes three segments. The last number is the string’s length, not the start of a fourth sentence. There is no need to append an extra end marker. For empty input, the API returns `[0]`; the slicing loop then runs zero times.

These offsets can be used directly with C# ranges on the original string. Do not interpret them as UTF-8 byte positions, and do not trim or otherwise change the string before applying them. If a display should omit trailing spaces, retain the original range separately from the displayed text so selections still refer to the correct source positions.

The API does not need a font, a locale setting or a network request. All sample input is the literal string shown on the page, so the download can run without fetching data.

## How does Unicode sentence segmentation handle punctuation?

A full stop is not always a sentence end. The decimal in `It is 3.5 ok.` stays within one segment. The documented rules consider terminators, closing quotes or brackets, and following whitespace; they can keep a full stop within a number, an initial or a lowercase continuation. Splitting on every period loses that context.

The default rules cannot answer every language-specific question about abbreviations. onefont’s API explicitly has no abbreviation list. If your input has domain-specific abbreviations, editorial conventions or ambiguous punctuation, default sentence boundaries are not a promise that each segment is a linguistically complete sentence. Keep the original text available for any application-specific decisions.

The [Unicode sentence-boundary specification](https://www.unicode.org/reports/tr29/#Sentence_Boundaries) describes the default algorithm and the role of tailoring. Choose this API for those default rules, not for an abbreviation-aware natural-language pipeline.

## How is sentence segmentation different from grapheme segmentation?

Sentence segmentation returns spans for sentence-by-sentence operations. Grapheme segmentation returns smaller spans that keep combining characters and joined sequences together. Neither one measures how much space text occupies on screen, and neither one chooses line breaks to fit a column.

The variation’s `FillSentenceStarts` gives the same sentence boundaries as byte flags instead of an integer array. Reserve `text.Length + 1` bytes: the terminal position is always marked. A buffer that is too short throws `ArgumentException`; entries beyond the required range are not touched. Use the array when you want to enumerate sentences and the flags when another operation needs to ask whether a particular UTF-16 offset is a boundary.
