---
title: "getTextBeforeSelection"
description: "Returns the text before the selection."
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun TextFieldValue.getTextBeforeSelection(maxChars: Int): AnnotatedString
```


Returns the text before the selection.

#### Parameters

| | |
| --- | --- |
| maxChars | maximum number of characters (inclusive) before the minimum value in `TextFieldValue.selection`. |




