W3cubDocs

/Kotlin

setLength

Platform and version requirements: JS (1.4), Native (1.3)
fun setLength(newLength: Int)

Sets the length of this string builder to the specified newLength.

If the newLength is less than the current length, it is changed to the specified newLength. Otherwise, null characters '\u0000' are appended to this string builder until its length is less than the newLength.

Note that in Kotlin/JS set operator function has non-constant execution time complexity. Therefore, increasing length of this string builder and then updating each character by index may slow down your program.

Exceptions

IndexOutOfBoundsException - or IllegalArgumentException if newLength is less than zero.

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-string-builder/set-length.html