I'm using Composables in Android Studio Kotlin, It creates a spanned string via specified keywords via looking up within foreach loop, How to make it append just one time or remove duplicated appended text?
buildAnnotatedString {
note.value.title.forEachIndexed { index, character ->
append(character)
if (index > queryString.count() - 1 && note.value.title.substring(
index - (queryString.count() + 1 - 1), index
) == queryString
) {
withStyle(style = SpanStyle(color = Color.Blue))
{
append(queryString)
}
}
}
}
Actually its not possible to avoid writing two times or reverse code and delete duplicates