---
title: "buildAnnotatedString"
description: "Build a new AnnotatedString by populating newly created [AnnotatedString.Builder] provided by
[builder]."
type: "function"
---

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


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


```kotlin
inline fun buildAnnotatedString(builder: (Builder).() -> Unit): AnnotatedString
```


Build a new AnnotatedString by populating newly created `AnnotatedString.Builder` provided by
`builder`.

#### Parameters

| | |
| --- | --- |
| builder | lambda to modify `AnnotatedString.Builder` |




## Code Examples
### AnnotatedStringBuilderLambdaSample
```kotlin
fun AnnotatedStringBuilderLambdaSample() {
    // create an AnnotatedString using the lambda builder
    buildAnnotatedString {
        // append "Hello" with red text color
        withStyle(SpanStyle(color = Color.Red)) { append("Hello") }
        append(" ")
        // append "Hello" with blue text color
        withStyle(SpanStyle(color = Color.Blue)) { append("World!") }
    }
}
```

