StringBuilder

A mutable sequence of characters.

String builder can be used to efficiently perform multiple string manipulation operations.

Since Kotlin

1.0

A mutable sequence of characters.

String builder can be used to efficiently perform multiple string manipulation operations.

Since Kotlin

1.1

Since Kotlin

1.1

A mutable sequence of characters.

String builder can be used to efficiently perform multiple string manipulation operations.

Since Kotlin

1.3

Constructors

Link copied to clipboard
expect constructor()

Constructs an empty string builder.

expect constructor(capacity: Int)

Constructs an empty string builder with the specified initial capacity.

expect constructor(content: CharSequence)

Constructs a string builder that contains the same characters as the specified content char sequence.

expect constructor(content: String)

Constructs a string builder that contains the same characters as the specified content string.

actual constructor()

Constructs an empty string builder.

actual constructor(capacity: Int)

Constructs an empty string builder with the specified initial capacity.

actual constructor(content: CharSequence)

Constructs a string builder that contains the same characters as the specified content char sequence.

actual constructor(content: String)
actual constructor()

Constructs an empty string builder.

actual constructor(capacity: Int)

Constructs an empty string builder with the specified initial capacity.

actual constructor(content: CharSequence)

Constructs a string builder that contains the same characters as the specified content char sequence.

actual constructor(content: String)

Constructs a string builder that contains the same characters as the specified content string.

Properties

Link copied to clipboard

Returns the range of valid character indices for this char sequence.

Since Kotlin 1.0
Link copied to clipboard

Returns the index of the last character in the char sequence or -1 if it is empty.

Since Kotlin 1.0
Link copied to clipboard
expect open override val length: Int

Returns the length of this character sequence.

Since Kotlin 1.0
actual open override val length: Int

Returns the length of this character sequence.

Since Kotlin 1.1
actual open override val length: Int

Returns the length of this character sequence.

Since Kotlin 1.3

Functions

Link copied to clipboard
inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean

Returns true if all characters match the given predicate.

Since Kotlin 1.0
Link copied to clipboard

Returns true if char sequence has at least one character.

Since Kotlin 1.0
inline fun CharSequence.any(predicate: (Char) -> Boolean): Boolean

Returns true if at least one character matches the given predicate.

Since Kotlin 1.0
Link copied to clipboard
expect fun append(value: Any?): StringBuilder

Appends the string representation of the specified object value to this string builder and returns this instance.

Since Kotlin 1.0
expect fun append(value: Boolean): StringBuilder

Appends the string representation of the specified boolean value to this string builder and returns this instance.

Since Kotlin 1.3
expect open override fun append(value: Char): StringBuilder

Appends the specified character value to this Appendable and returns this instance.

Since Kotlin 1.0
expect fun append(value: CharArray): StringBuilder

Appends characters in the specified character array value to this string builder and returns this instance.

Since Kotlin 1.4
expect open override fun append(value: CharSequence?): StringBuilder

Appends the specified character sequence value to this Appendable and returns this instance.

Since Kotlin 1.0
expect fun append(value: String?): StringBuilder

Appends the specified string value to this string builder and returns this instance.

Since Kotlin 1.3
expect open override fun append(value: CharSequence?, startIndex: Int, endIndex: Int): StringBuilder

Appends a subsequence of the specified character sequence value to this Appendable and returns this instance.

Since Kotlin 1.0
actual fun append(value: Any?): StringBuilder

Appends the string representation of the specified object value to this string builder and returns this instance.

Since Kotlin 1.1
actual fun append(value: Boolean): StringBuilder

Appends the string representation of the specified boolean value to this string builder and returns this instance.

Since Kotlin 1.3
actual open override fun append(value: Char): StringBuilder

Appends the specified character value to this Appendable and returns this instance.

Since Kotlin 1.1
actual fun append(value: CharArray): StringBuilder

Appends characters in the specified character array value to this string builder and returns this instance.

Since Kotlin 1.4
actual open override fun append(value: CharSequence?): StringBuilder

Appends the specified character sequence value to this Appendable and returns this instance.

Since Kotlin 1.1
actual fun append(value: String?): StringBuilder

Appends the specified string value to this string builder and returns this instance.

Since Kotlin 1.3
actual open override fun append(value: CharSequence?, startIndex: Int, endIndex: Int): StringBuilder

Appends a subsequence of the specified character sequence value to this Appendable and returns this instance.

Since Kotlin 1.1
actual fun append(value: Any?): StringBuilder

Appends the string representation of the specified object value to this string builder and returns this instance.

Since Kotlin 1.3
actual fun append(value: Boolean): StringBuilder

Appends the string representation of the specified boolean value to this string builder and returns this instance.

Since Kotlin 1.3
fun append(value: Int): StringBuilder
Since Kotlin 1.3
actual open override fun append(value: Char): StringBuilder

Appends the specified character value to this Appendable and returns this instance.

Since Kotlin 1.3
actual fun append(value: CharArray): StringBuilder

Appends characters in the specified character array value to this string builder and returns this instance.

Since Kotlin 1.3
actual open override fun append(value: CharSequence?): StringBuilder

Appends the specified character sequence value to this Appendable and returns this instance.

Since Kotlin 1.3
actual fun append(value: String?): StringBuilder

Appends the specified string value to this string builder and returns this instance.

Since Kotlin 1.3
actual open override fun append(value: CharSequence?, startIndex: Int, endIndex: Int): StringBuilder

Appends a subsequence of the specified character sequence value to this Appendable and returns this instance.

Since Kotlin 1.3
Link copied to clipboard
Since Kotlin 1.0
fun StringBuilder.append(vararg value: Any?): StringBuilder

Appends all arguments to the given StringBuilder.

Since Kotlin 1.0
Link copied to clipboard

Appends a line feed character (\n) to this Appendable.

Since Kotlin 1.4

Appends a line feed character (\n) to this StringBuilder.

Since Kotlin 1.4
inline fun Appendable.appendLine(value: Char): Appendable

Appends value to the given Appendable and a line feed character (\n) after it.

Since Kotlin 1.4

Appends value to this StringBuilder, followed by a line feed character (\n).

Since Kotlin 1.4

Appends value to this StringBuilder, followed by a line feed character (\n).

Since Kotlin 1.4

Appends value to this StringBuilder, followed by a line feed character (\n).

Since Kotlin 1.4
Link copied to clipboard

Appends a line separator to this Appendable.

Since Kotlin 1.0

Appends a line separator to this StringBuilder.

Since Kotlin 1.0
inline fun Appendable.appendln(value: Char): Appendable

Appends value to the given Appendable and line separator after it.

Since Kotlin 1.0

Appends value to this StringBuilder, followed by a line separator.

Since Kotlin 1.0
Link copied to clipboard
fun appendRange(value: CharArray, startIndex: Int, endIndex: Int): StringBuilder

Appends characters in a subarray of the specified character array value to this string builder and returns this instance.

Since Kotlin 1.4
fun appendRange(value: CharSequence, startIndex: Int, endIndex: Int): StringBuilder

Appends a subsequence of the specified character sequence value to this string builder and returns this instance.

Since Kotlin 1.4
fun appendRange(value: CharArray, startIndex: Int, endIndex: Int): StringBuilder

Appends characters in a subarray of the specified character array value to this string builder and returns this instance.

Since Kotlin 1.4
fun appendRange(value: CharSequence, startIndex: Int, endIndex: Int): StringBuilder

Appends a subsequence of the specified character sequence value to this string builder and returns this instance.

Since Kotlin 1.4
Link copied to clipboard
expect fun StringBuilder.appendRange(value: CharArray, startIndex: Int, endIndex: Int): StringBuilder

Appends characters in a subarray of the specified character array value to this string builder and returns this instance.

Since Kotlin 1.4
expect fun StringBuilder.appendRange(value: CharSequence, startIndex: Int, endIndex: Int): StringBuilder

Appends a subsequence of the specified character sequence value to this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.appendRange(value: CharArray, startIndex: Int, endIndex: Int): StringBuilder

Appends characters in a subarray of the specified character array value to this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.appendRange(value: CharSequence, startIndex: Int, endIndex: Int): StringBuilder

Appends a subsequence of the specified character sequence value to this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.appendRange(value: CharArray, startIndex: Int, endIndex: Int): StringBuilder

Appends characters in a subarray of the specified character array value to this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.appendRange(value: CharSequence, startIndex: Int, endIndex: Int): StringBuilder

Appends a subsequence of the specified character sequence value to this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.appendRange(value: CharArray, startIndex: Int, endIndex: Int): StringBuilder

Appends characters in a subarray of the specified character array value to this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.appendRange(value: CharSequence, startIndex: Int, endIndex: Int): StringBuilder

Appends a subsequence of the specified character sequence value to this string builder and returns this instance.

Since Kotlin 1.4
Link copied to clipboard

Creates an Iterable instance that wraps the original char sequence returning its characters when being iterated.

Since Kotlin 1.0
Link copied to clipboard

Creates a Sequence instance that wraps the original char sequence returning its characters when being iterated.

Since Kotlin 1.0
Link copied to clipboard
inline fun <K, V> CharSequence.associate(transform: (Char) -> Pair<K, V>): Map<K, V>

Returns a Map containing key-value pairs provided by transform function applied to characters of the given char sequence.

Since Kotlin 1.0
Link copied to clipboard
inline fun <K> CharSequence.associateBy(keySelector: (Char) -> K): Map<K, Char>

Returns a Map containing the characters from the given char sequence indexed by the key returned from keySelector function applied to each character.

Since Kotlin 1.0
inline fun <K, V> CharSequence.associateBy(keySelector: (Char) -> K, valueTransform: (Char) -> V): Map<K, V>

Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to characters of the given char sequence.

Since Kotlin 1.0
Link copied to clipboard
inline fun <K, M : MutableMap<in K, in Char>> CharSequence.associateByTo(destination: M, keySelector: (Char) -> K): M

Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function applied to each character of the given char sequence and value is the character itself.

Since Kotlin 1.0
inline fun <K, V, M : MutableMap<in K, in V>> CharSequence.associateByTo(destination: M, keySelector: (Char) -> K, valueTransform: (Char) -> V): M

Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function and and value is provided by the valueTransform function applied to characters of the given char sequence.

Since Kotlin 1.0
Link copied to clipboard
inline fun <K, V, M : MutableMap<in K, in V>> CharSequence.associateTo(destination: M, transform: (Char) -> Pair<K, V>): M

Populates and returns the destination mutable map with key-value pairs provided by transform function applied to each character of the given char sequence.

Since Kotlin 1.0
Link copied to clipboard
inline fun <V> CharSequence.associateWith(valueSelector: (Char) -> V): Map<Char, V>

Returns a Map where keys are characters from the given char sequence and values are produced by the valueSelector function applied to each character.

Since Kotlin 1.3
Link copied to clipboard
inline fun <V, M : MutableMap<in Char, in V>> CharSequence.associateWithTo(destination: M, valueSelector: (Char) -> V): M

Populates and returns the destination mutable map with key-value pairs for each character of the given char sequence, where key is the character itself and value is provided by the valueSelector function applied to that key.

Since Kotlin 1.3
Link copied to clipboard
expect fun capacity(): Int

Returns the current capacity of this string builder.

Since Kotlin 1.3
actual fun capacity(): Int

Returns the current capacity of this string builder.

Since Kotlin 1.3
actual fun capacity(): Int

Returns the current capacity of this string builder.

Since Kotlin 1.3
Link copied to clipboard

Splits this char sequence into a list of strings each not exceeding the given size.

Since Kotlin 1.2
fun <R> CharSequence.chunked(size: Int, transform: (CharSequence) -> R): List<R>

Splits this char sequence into several char sequences each not exceeding the given size and applies the given transform function to an each.

Since Kotlin 1.2
Link copied to clipboard

Splits this char sequence into a sequence of strings each not exceeding the given size.

Since Kotlin 1.2
fun <R> CharSequence.chunkedSequence(size: Int, transform: (CharSequence) -> R): Sequence<R>

Splits this char sequence into several char sequences each not exceeding the given size and applies the given transform function to an each.

Since Kotlin 1.2
Link copied to clipboard

Clears the content of this string builder making it empty and returns this instance.

Since Kotlin 1.3
Link copied to clipboard

Clears the content of this string builder making it empty and returns this instance.

Since Kotlin 1.3
actual inline fun StringBuilder.clear(): StringBuilder

Clears the content of this string builder making it empty and returns this instance.

Since Kotlin 1.3

Clears the content of this string builder making it empty and returns this instance.

Since Kotlin 1.3

Clears the content of this string builder making it empty and returns this instance.

Since Kotlin 1.3
Link copied to clipboard
fun CharSequence.commonPrefixWith(other: CharSequence, ignoreCase: Boolean = false): String

Returns the longest string prefix such that this char sequence and other char sequence both start with this prefix, taking care not to split surrogate pairs. If this and other have no common prefix, returns the empty string.

Since Kotlin 1.0
Link copied to clipboard
fun CharSequence.commonSuffixWith(other: CharSequence, ignoreCase: Boolean = false): String

Returns the longest string suffix such that this char sequence and other char sequence both end with this suffix, taking care not to split surrogate pairs. If this and other have no common suffix, returns the empty string.

Since Kotlin 1.0
Link copied to clipboard
inline operator fun CharSequence.contains(regex: Regex): Boolean

Returns true if this char sequence contains at least one match of the specified regular expression regex.

Since Kotlin 1.0
operator fun CharSequence.contains(char: Char, ignoreCase: Boolean = false): Boolean

Returns true if this char sequence contains the specified character char.

Since Kotlin 1.0
operator fun CharSequence.contains(other: CharSequence, ignoreCase: Boolean = false): Boolean

Returns true if this char sequence contains the specified other sequence of characters as a substring.

Since Kotlin 1.0
Link copied to clipboard
expect infix fun CharSequence?.contentEquals(other: CharSequence?): Boolean

Returns true if the contents of this char sequence are equal to the contents of the specified other, i.e. both char sequences contain the same number of the same characters in the same order.

Since Kotlin 1.5
expect fun CharSequence?.contentEquals(other: CharSequence?, ignoreCase: Boolean): Boolean

Returns true if the contents of this char sequence are equal to the contents of the specified other, optionally ignoring case difference.

Since Kotlin 1.5
actual infix fun CharSequence?.contentEquals(other: CharSequence?): Boolean

Returns true if the contents of this char sequence are equal to the contents of the specified other, i.e. both char sequences contain the same number of the same characters in the same order.

Since Kotlin 1.5
actual fun CharSequence?.contentEquals(other: CharSequence?, ignoreCase: Boolean): Boolean

Returns true if the contents of this char sequence are equal to the contents of the specified other, optionally ignoring case difference.

Since Kotlin 1.5
actual infix fun CharSequence?.contentEquals(other: CharSequence?): Boolean

Returns true if the contents of this char sequence are equal to the contents of the specified other, i.e. both char sequences contain the same number of the same characters in the same order.

Since Kotlin 1.5
actual fun CharSequence?.contentEquals(other: CharSequence?, ignoreCase: Boolean): Boolean

Returns true if the contents of this char sequence are equal to the contents of the specified other, optionally ignoring case difference.

Since Kotlin 1.5
actual infix fun CharSequence?.contentEquals(other: CharSequence?): Boolean

Returns true if the contents of this char sequence are equal to the contents of the specified other, i.e. both char sequences contain the same number of the same characters in the same order.

Since Kotlin 1.5
actual fun CharSequence?.contentEquals(other: CharSequence?, ignoreCase: Boolean): Boolean

Returns true if the contents of this char sequence are equal to the contents of the specified other, optionally ignoring case difference.

Since Kotlin 1.5
Link copied to clipboard
inline fun CharSequence.count(): Int

Returns the length of this char sequence.

Since Kotlin 1.0
inline fun CharSequence.count(predicate: (Char) -> Boolean): Int

Returns the number of characters matching the given predicate.

Since Kotlin 1.0
Link copied to clipboard

Removes the character at the specified index from this string builder and returns this instance.

Since Kotlin 1.4

Removes the character at the specified index from this string builder and returns this instance.

Since Kotlin 1.4
Link copied to clipboard

Removes the character at the specified index from this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.deleteAt(index: Int): StringBuilder

Removes the character at the specified index from this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.deleteAt(index: Int): StringBuilder

Removes the character at the specified index from this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.deleteAt(index: Int): StringBuilder

Removes the character at the specified index from this string builder and returns this instance.

Since Kotlin 1.4
Link copied to clipboard

Removes the character at the specified index from this string builder and returns this instance.

Since Kotlin 1.3
Link copied to clipboard
fun deleteRange(startIndex: Int, endIndex: Int): StringBuilder

Removes characters in the specified range from this string builder and returns this instance.

Since Kotlin 1.4
fun deleteRange(startIndex: Int, endIndex: Int): StringBuilder

Removes characters in the specified range from this string builder and returns this instance.

Since Kotlin 1.4
Link copied to clipboard
expect fun StringBuilder.deleteRange(startIndex: Int, endIndex: Int): StringBuilder

Removes characters in the specified range from this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.deleteRange(startIndex: Int, endIndex: Int): StringBuilder

Removes characters in the specified range from this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.deleteRange(startIndex: Int, endIndex: Int): StringBuilder

Removes characters in the specified range from this string builder and returns this instance.

Since Kotlin 1.4
actual inline fun StringBuilder.deleteRange(startIndex: Int, endIndex: Int): StringBuilder

Removes characters in the specified range from this string builder and returns this instance.

Since Kotlin 1.4
Link copied to clipboard

Returns a subsequence of this char sequence with the first n characters removed.

Since Kotlin 1.0
Link copied to clipboard

Returns a subsequence of this char sequence with the last n characters removed.

Since Kotlin 1.0
Link copied to clipboard
inline fun CharSequence.dropLastWhile(predicate: (Char) -> Boolean): CharSequence

Returns a subsequence of this char sequence containing all characters except last characters that satisfy the given predicate.

Since Kotlin 1.0
Link copied to clipboard
inline fun CharSequence.dropWhile(predicate: (Char) -> Boolean): CharSequence

Returns a subsequence of this char sequence containing all characters except first characters that satisfy the given predicate.

Since Kotlin 1.0
Link copied to clipboard
expect fun CharSequence.elementAt(index: Int): Char

Returns a character at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this char sequence.

Since Kotlin 1.0
actual fun CharSequence.elementAt(index: Int): Char

Returns a character at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this char sequence.

Since Kotlin 1.1
actual inline fun CharSequence.elementAt(index: Int): Char

Returns a character at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this char sequence.

Since Kotlin 1.0
actual inline fun CharSequence.elementAt(index: Int): Char

Returns a character at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this char sequence.

Since Kotlin 1.3
Link copied to clipboard
inline fun CharSequence.elementAtOrElse(index: Int, defaultValue: (Int) -> Char): Char

Returns a character at the given index or the result of calling the defaultValue function if the index is out of bounds of this char sequence.

Since Kotlin 1.0
Link copied to clipboard
inline fun CharSequence.elementAtOrNull(index: Int): Char?

Returns a character at the given index or null if the index is out of bounds of this char sequence.

Since Kotlin 1.0
Link copied to clipboard
fun CharSequence.endsWith(char: Char, ignoreCase: Boolean = false): Boolean

Returns true if this char sequence ends with the specified character.

Since Kotlin 1.0
fun CharSequence.endsWith(suffix: CharSequence, ignoreCase: Boolean = false): Boolean

Returns true if this char sequence ends with the specified suffix.

Since Kotlin 1.0
Link copied to clipboard
expect fun ensureCapacity(minimumCapacity: Int)

Ensures that the capacity of this string builder is at least equal to the specified minimumCapacity.

Since Kotlin 1.4
actual fun ensureCapacity(minimumCapacity: Int)

Ensures that the capacity of this string builder is at least equal to the specified minimumCapacity.

Since Kotlin 1.4
actual fun ensureCapacity(minimumCapacity: Int)

Ensures that the capacity of this string builder is at least equal to the specified minimumCapacity.

Since Kotlin 1.3
Link copied to clipboard
inline fun StringBuilder.ensureCapacity(capacity: Int)
Since Kotlin 1.3
Link copied to clipboard
inline fun CharSequence.filter(predicate: (Char) -> Boolean): CharSequence

Returns a char sequence containing only those characters from the original char sequence that match the given predicate.

Since Kotlin 1.0
Link copied to clipboard
inline fun CharSequence.