Package kotlin.text

Functions for working with text and regular expressions.

Types

Appendable

An object to which char sequences and values can be appended.

Common
JS
Native
1.0
interface Appendable
JVM
1.1
typealias Appendable = Appendable
Common
JVM
JS
Native
1.0

CharCategory

Represents the character general category in the Unicode specification.

enum class CharCategory
JVM
1.0

CharDirectionality

Represents the Unicode directionality of a character. Character directionality is used to calculate the visual ordering of text.

enum class CharDirectionality
JVM
1.0

Charsets

Constant definitions for the standard charsets. These charsets are guaranteed to be available on every implementation of the Java platform.

object Charsets
Common
JVM
JS
Native
1.9

HexFormat

Represents hexadecimal format options for formatting and parsing byte arrays and integer numeric values, both signed and unsigned.

class HexFormat

MatchGroup

Represents the results from a single capturing group within a MatchResult of Regex.

Common
1.0
class MatchGroup
JVM
JS
Native
1.0
data class MatchGroup
Common
JVM
JS
Native
1.0

MatchGroupCollection

Represents a collection of captured groups in a single match of a regular expression.

interface MatchGroupCollection : Collection<MatchGroup?>
Common
JVM
JS
Native
1.1

MatchNamedGroupCollection

Extends MatchGroupCollection by introducing a way to get matched groups by name, when regex supports it.

interface MatchNamedGroupCollection : MatchGroupCollection
Common
JVM
JS
Native
1.0

MatchResult

Represents the results from a single regular expression match.

interface MatchResult

Regex

Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.

Common
JS
Native
1.0
class Regex
JVM
1.0
class Regex : Serializable

RegexOption

Provides enumeration values to use to set regular expression options.

Common
JS
Native
1.0
enum class RegexOption
JVM
1.0
enum class RegexOption : FlagEnum

StringBuilder

A mutable sequence of characters.

Common
JS
1.0
class StringBuilder : Appendable, CharSequence
JVM
1.1
typealias StringBuilder = StringBuilder
Native
1.3
class StringBuilder : CharSequence, Appendable
Common
JVM
JS
Native
1.0

Typography

Defines names for Unicode symbols used in proper Typography.

object Typography

Exceptions

CharacterCodingException

The exception thrown when a character encoding or decoding error occurs.

Common
JS
Native
1.3
open class CharacterCodingException : Exception
JVM
1.4
typealias CharacterCodingException = CharacterCodingException

Extensions for External Classes

Properties

Common
JVM
JS
Native
1.0

category

Returns the Unicode general category of this character.

val Char.category: CharCategory
JVM
1.0

directionality

Returns the Unicode directionality property for the given character.

val Char.directionality: CharDirectionality
Common
JVM
JS
Native
1.0

indices

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

val CharSequence.indices: IntRange
Common
JVM
JS
Native
1.0

lastIndex

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

val CharSequence.lastIndex: Int

Functions

Common
JVM
JS
Native
1.0

all

Returns true if all characters match the given predicate.

fun CharSequence.all(predicate: (Char) -> Boolean): Boolean
Common
JVM
JS
Native
1.0

any

Returns true if char sequence has at least one character.

fun CharSequence.any(): Boolean

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

fun CharSequence.any(predicate: (Char) -> Boolean): Boolean

append

Common
JVM
JS
Native
1.0

Appends all arguments to the given Appendable.

fun <T : Appendable> T.append(vararg value: CharSequence?): T
Common
JVM
JS
Native
1.0
fun StringBuilder.append(obj: Any?): StringBuilder
fun StringBuilder.append(
    str: CharArray,
    offset: Int,
    len: Int
): StringBuilder
Common
JVM
JS
Native
1.0

Appends all arguments to the given StringBuilder.

fun StringBuilder.append(
    vararg value: String?
): StringBuilder
fun StringBuilder.append(vararg value: Any?): StringBuilder
Common
JS
Native
1.9

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

fun StringBuilder.append(value: Byte): StringBuilder
Common
JS
Native
1.9

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

fun StringBuilder.append(value: Short): StringBuilder

appendLine

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

Common
JVM
JS
Native
1.4
fun Appendable.appendLine(): Appendable

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

Common
JVM
JS
Native
1.4
fun Appendable.appendLine(value: CharSequence?): Appendable
Common
JVM
JS
Native
1.4
fun Appendable.appendLine(value: Char): Appendable

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

Common
JVM
JS
Native
1.4
fun StringBuilder.appendLine(): StringBuilder

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

Common
JVM
JS
Native
1.4
fun StringBuilder.appendLine(
    value: CharSequence?
): StringBuilder
Common
JVM
JS
Native
1.4
fun StringBuilder.appendLine(value: String?): StringBuilder
Common
JVM
JS
Native
1.4
fun StringBuilder.appendLine(value: Any?): StringBuilder
Common
JVM
JS
Native
1.4
fun StringBuilder.appendLine(value: CharArray): StringBuilder
Common
JVM
JS
Native
1.4
fun StringBuilder.appendLine(value: Char): StringBuilder
Common
JVM
JS
Native
1.4
fun StringBuilder.appendLine(value: Boolean): StringBuilder
Common
JS
Native
1.4
fun StringBuilder.appendLine(value: Byte): StringBuilder
Common
JS
Native
1.4
fun StringBuilder.appendLine(value: Short): StringBuilder
Common
JS
Native
1.4
fun StringBuilder.appendLine(value: Int): StringBuilder
Common
JS
Native
1.4
fun StringBuilder.appendLine(value: Long): StringBuilder
Common
JS
Native
1.4
fun StringBuilder.appendLine(value: Float): StringBuilder
Common
JS
Native
1.4
fun StringBuilder.appendLine(value: Double): StringBuilder
Native
1.3

appendln

fun StringBuilder.appendln(it: String): StringBuilder
fun StringBuilder.appendln(it: Boolean): StringBuilder
fun StringBuilder.appendln(it: Byte): StringBuilder
fun StringBuilder.appendln(it: Short): StringBuilder
fun StringBuilder.appendln(it: Int): StringBuilder
fun StringBuilder.appendln(it: Long): StringBuilder
fun StringBuilder.appendln(it: Float): StringBuilder
fun StringBuilder.appendln(it: Double): StringBuilder
fun StringBuilder.appendln(it: Any?): StringBuilder

appendRange

Common
JVM
JS
Native
1.4

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

fun <T : Appendable> T.appendRange(
    value: CharSequence,
    startIndex: Int,
    endIndex: Int
): T
Common
JS
Native
1.4

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

fun StringBuilder.appendRange(
    value: CharArray,
    startIndex: Int,
    endIndex: Int
): StringBuilder
Common
JS
Native
1.4

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

fun StringBuilder.appendRange(
    value: CharSequence,
    startIndex: Int,
    endIndex: Int
): StringBuilder
Common
JVM
JS
Native
1.0

asIterable

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

fun CharSequence.asIterable(): Iterable<Char>
Common
JVM
JS
Native
1.0

asSequence

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

fun CharSequence.asSequence(): Sequence<Char>
Common
JVM
JS
Native
1.0

associate

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

fun <K, V> CharSequence.associate(
    transform: (Char) -> Pair<K, V>
): Map<K, V>
Common
JVM
JS
Native
1.0

associateBy

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

fun <K> CharSequence.associateBy(
    keySelector: (Char) -> K
): Map<K, Char>

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

fun <K, V> CharSequence.associateBy(
    keySelector: (Char) -> K,
    valueTransform: (Char) -> V
): Map<K, V>
Common
JVM
JS
Native
1.0

associateByTo

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.

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 and and value is provided by the valueTransform function applied to characters of the given char sequence.

fun <K, V, M : MutableMap<in K, in V>> CharSequence.associateByTo(
    destination: M,
    keySelector: (Char) -> K,
    valueTransform: (Char) -> V
): M
Common
JVM
JS
Native
1.0

associateTo

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

fun <K, V, M : MutableMap<in K, in V>> CharSequence.associateTo(
    destination: M,
    transform: (Char) -> Pair<K, V>
): M
Common
JVM
JS
Native
1.3

associateWith

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

fun <V> CharSequence.associateWith(
    valueSelector: (Char) -> V
): Map<Char, V>
Common
JVM
JS
Native
1.3

associateWithTo

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.

fun <V, M : MutableMap<in Char, in V>> CharSequence.associateWithTo(
    destination: M,
    valueSelector: (Char) -> V
): M
Common
JVM
JS
Native
1.0

buildString

Builds new string by populating newly created StringBuilder using provided builderAction and then converting it to String.

fun buildString(
    builderAction: StringBuilder.() -> Unit
): String

Builds new string by populating newly created StringBuilder initialized with the given capacity using provided builderAction and then converting it to String.

fun buildString(
    capacity: Int,
    builderAction: StringBuilder.() -> Unit
): String

capitalize

JVM
1.4

Returns a copy of this string having its first letter titlecased using the rules of the specified locale, or the original string if it's empty or already starts with a title case letter.

fun String.capitalize(locale: Locale): String
Common
JVM
JS
Native
1.0

Returns a copy of this string having its first letter titlecased using the rules of the default locale, or the original string if it's empty or already starts with a title case letter.

fun String.capitalize(): String
JVM
1.0

charset

Returns a named charset with the given charsetName name.

fun charset(charsetName: String): Charset
Common
JVM
JS
Native
1.2

chunked

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

fun CharSequence.chunked(size: Int): List<String>

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

fun <R> CharSequence.chunked(
    size: Int,
    transform: (CharSequence) -> R
): List<R>
Common
JVM
JS
Native
1.2

chunkedSequence

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

fun CharSequence.chunkedSequence(size: Int): Sequence<String>

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

fun <R> CharSequence.chunkedSequence(
    size: Int,
    transform: (CharSequence) -> R
): Sequence<R>
Common
JS
Native
1.3

clear

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

JVM
1.0

codePointAt

Returns the character (Unicode code point) at the specified index.

fun String.codePointAt(index: Int): Int
JVM
1.0

codePointBefore

Returns the character (Unicode code point) before the specified index.

fun String.codePointBefore(index: Int): Int
JVM
1.0

codePointCount

Returns the number of Unicode code points in the specified text range of this String.

fun String.codePointCount(
    beginIndex: Int,
    endIndex: Int
): Int
Common
JVM
JS
Native
1.0

commonPrefixWith

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.

fun CharSequence.commonPrefixWith(
    other: CharSequence,
    ignoreCase: Boolean = false
): String
Common
JVM
JS
Native
1.0

commonSuffixWith

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.

fun CharSequence.commonSuffixWith(
    other: CharSequence,
    ignoreCase: Boolean = false
): String
Common
JVM
JS
Native
1.0

compareTo

Compares two strings lexicographically, optionally ignoring case differences.

fun String.compareTo(
    other: String,
    ignoreCase: Boolean = false
): Int
JS
1.1

concat

fun String.concat(str: String): String
Common
JVM
JS
Native
1.3

concatToString

Concatenates characters in this CharArray into a String.

fun CharArray.concatToString(): String

Concatenates characters in this CharArray or its subrange into a String.

fun CharArray.concatToString(
    startIndex: Int = 0,
    endIndex: Int = this.size
): String
Common
JVM
JS
Native
1.0

contains

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

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

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

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

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

operator fun CharSequence.contains(regex: Regex): Boolean

contentEquals

JVM
1.0

Returns true if this string is equal to the contents of the specified CharSequence, false otherwise.

fun String.contentEquals(charSequence: CharSequence): Boolean
JVM
1.0

Returns true if this string is equal to the contents of the specified StringBuffer, false otherwise.

fun String.contentEquals(
    stringBuilder: StringBuffer
): Boolean
Common
JVM
JS
Native
1.5

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.

infix fun CharSequence?.contentEquals(
    other: CharSequence?
): Boolean
Common
JVM
JS
Native
1.5

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

fun CharSequence?.contentEquals(
    other: CharSequence?,
    ignoreCase: Boolean
): Boolean
Common
JVM
JS
Native
1.0

count

Returns the length of this char sequence.

fun CharSequence.count(): Int

Returns the number of characters matching the given predicate.

fun CharSequence.count(predicate: (Char) -> Boolean): Int

decapitalize

JVM
1.4

Returns a copy of this string having its first letter lowercased using the rules of the specified locale, or the original string, if it's empty or already starts with a lower case letter.

fun String.decapitalize(locale: Locale): String
Common
JVM
JS
Native
1.0

Returns a copy of this string having its first letter lowercased using the rules of the default locale, or the original string if it's empty or already starts with a lower case letter.

fun String.decapitalize(): String
Common
JVM
JS
Native
1.3

decodeToString

Decodes a string from the bytes in UTF-8 encoding in this array.

fun ByteArray.decodeToString(): String

Decodes a string from the bytes in UTF-8 encoding in this array or its subrange.

fun ByteArray.decodeToString(
    startIndex: Int = 0,
    endIndex: Int = this.size,
    throwOnInvalidSequence: Boolean = false
): String
Common
JS
Native
1.4

deleteAt

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

fun StringBuilder.deleteAt(index: Int): StringBuilder
Native
1.3

deleteCharAt

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

fun StringBuilder.deleteCharAt(index: Int): StringBuilder
Common
JS
Native
1.4

deleteRange

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

fun StringBuilder.deleteRange(
    startIndex: Int,
    endIndex: Int
): StringBuilder
Common
JVM
JS
Native
1.5

digitToChar

Returns the Char that represents this decimal digit. Throws an exception if this value is not in the range 0..9.

fun Int.digitToChar(): Char

Returns the Char that represents this numeric digit value in the specified radix. Throws an exception if the radix is not in the range 2..36 or if this value is not in the range 0 until radix.

fun Int.digitToChar(radix: Int): Char
Common
JVM
JS
Native
1.5

digitToInt

Returns the numeric value of the decimal digit that this Char represents. Throws an exception if this Char is not a valid decimal digit.

fun Char.digitToInt(): Int

Returns the numeric value of the digit that this Char represents in the specified radix. Throws an exception if the radix is not in the range 2..36 or if this Char is not a valid digit in the specified radix.

fun Char.digitToInt(radix: Int): Int
Common
JVM
JS
Native
1.5

digitToIntOrNull

Returns the numeric value of the decimal digit that this Char represents, or null if this Char is not a valid decimal digit.

fun Char.digitToIntOrNull(): Int?

Returns the numeric value of the digit that this Char represents in the specified radix, or null if this Char is not a valid digit in the specified radix. Throws an exception if the radix is not in the range 2..36.

fun Char.digitToIntOrNull(radix: Int): Int?
Common
JVM
JS
Native
1.0

drop

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

fun CharSequence.drop(n: Int): CharSequence

Returns a string with the first n characters removed.

fun String.drop(n: Int): String
Common
JVM
JS
Native
1.0

dropLast

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

fun CharSequence.dropLast(n: Int): CharSequence

Returns a string with the last n characters removed.

fun String.dropLast(n: Int): String
Common
JVM
JS
Native
1.0

dropLastWhile

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

fun CharSequence.dropLastWhile(
    predicate: (Char) -> Boolean
): CharSequence

Returns a string containing all characters except last characters that satisfy the given predicate.

fun String.dropLastWhile(
    predicate: (Char) -> Boolean
): String
Common
JVM
JS
Native
1.0

dropWhile

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

fun CharSequence.dropWhile(
    predicate: (Char) -> Boolean
): CharSequence

Returns a string containing all characters except first characters that satisfy the given predicate.

fun String.dropWhile(predicate: (Char) -> Boolean): String
Common
JVM
JS
Native
1.0

elementAt

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

fun CharSequence.elementAt(index: Int): Char
Common
JVM
JS
Native
1.0

elementAtOrElse

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.

fun CharSequence.elementAtOrElse(
    index: Int,
    defaultValue: (Int) -> Char
): Char
Common
JVM
JS
Native
1.0

elementAtOrNull

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

fun CharSequence.elementAtOrNull(index: Int): Char?
Common
JVM
JS
Native
1.3

encodeToByteArray

Encodes this string to an array of bytes in UTF-8 encoding.

fun String.encodeToByteArray(): ByteArray

Encodes this string or its substring to an array of bytes in UTF-8 encoding.

fun String.encodeToByteArray(
    startIndex: Int = 0,
    endIndex: Int = this.length,
    throwOnInvalidSequence: Boolean = false
): ByteArray
Common
JVM
JS
Native
1.0

endsWith

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

fun CharSequence.endsWith(
    char: Char,
    ignoreCase: Boolean = false
): Boolean

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

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

Returns true if this string ends with the specified suffix.

fun String.endsWith(
    suffix: String,
    ignoreCase: Boolean = false
): Boolean
Common
JVM
JS
Native
1.0

equals

Returns true if this character is equal to the other character, optionally ignoring character case.

fun Char.equals(
    other: Char,
    ignoreCase: Boolean = false
): Boolean

Returns true if this string is equal to other, optionally ignoring character case.

fun String?.equals(
    other: String?,
    ignoreCase: Boolean = false
): Boolean
Common
JVM
JS
Native
1.0

filter

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

fun CharSequence.filter(
    predicate: (Char) -> Boolean
): CharSequence

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

fun String.filter(predicate: (Char) -> Boolean): String
Common
JVM
JS
Native
1.0

filterIndexed

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

fun CharSequence.filterIndexed(
    predicate: (index: Int, Char) -> Boolean
): CharSequence

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

fun String.filterIndexed(
    predicate: (index: Int, Char) -> Boolean
): String
Common
JVM
JS
Native
1.0

filterIndexedTo

Appends all characters matching the given predicate to the given destination.

fun <C : Appendable> CharSequence.filterIndexedTo(
    destination: C,
    predicate: (index: Int, Char) -> Boolean
): C
Common
JVM
JS
Native
1.0

filterNot

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

fun CharSequence.filterNot(
    predicate: (Char) -> Boolean
): CharSequence

Returns a string containing only those characters from the original string that do not match the given predicate.

fun String.filterNot(predicate: (Char) -> Boolean): String
Common
JVM
JS
Native
1.0

filterNotTo

Appends all characters not matching the given predicate to the given destination.

fun <C : Appendable> CharSequence.filterNotTo(
    destination: C,
    predicate: (Char) -> Boolean
): C
Common
JVM
JS
Native
1.0

filterTo

Appends all characters matching the given predicate to the given destination.

fun <C : Appendable> CharSequence.filterTo(
    destination: C,
    predicate: (Char) -> Boolean
): C
Common
JVM
JS
Native
1.0

find

Returns the first character matching the given predicate, or null if no such character was found.

fun CharSequence.find(predicate: (Char) -> Boolean): Char?
Common
JVM
JS
Native
1.0

findAnyOf

Finds the first occurrence of any of the specified strings in this char sequence, starting from the specified startIndex and optionally ignoring the case.

fun CharSequence.findAnyOf(
    strings: Collection<String>,
    startIndex: Int = 0,
    ignoreCase: Boolean = false
): Pair<Int, String>?
Common
JVM
JS
Native
1.0

findLast

Returns the last character matching the given predicate, or null if no such character was found.

fun CharSequence.findLast(
    predicate: (Char) -> Boolean
): Char?
Common
JVM
JS
Native
1.0

findLastAnyOf

Finds the last occurrence of any of the specified strings in this char sequence, starting from the specified startIndex and optionally ignoring the case.

fun CharSequence.findLastAnyOf(
    strings: Collection<String>,
    startIndex: Int = lastIndex,
    ignoreCase: Boolean = false
): Pair<Int, String>?
Common
JVM
JS
Native
1.0

first

Returns the first character.

fun CharSequence.first(): Char

Returns the first character matching the given predicate.

fun CharSequence.first(predicate: (Char) -> Boolean): Char
Common
JVM
JS
Native
1.5

firstNotNullOf

Returns the first non-null value produced by transform function being applied to characters of this char sequence in iteration order, or throws NoSuchElementException if no non-null value was produced.

fun <R : Any> CharSequence.firstNotNullOf(
    transform: (Char) -> R?
): R
Common
JVM
JS
Native
1.5

firstNotNullOfOrNull

Returns the first non-null value produced by transform function being applied to characters of this char sequence in iteration order, or null if no non-null value was produced.

fun <R : Any> CharSequence.firstNotNullOfOrNull(
    transform: (Char) -> R?
): R?
Common
JVM
JS
Native
1.0

firstOrNull

Returns the first character, or null if the char sequence is empty.

fun CharSequence.firstOrNull(): Char?

Returns the first character matching the given predicate, or null if character was not found.

fun CharSequence.firstOrNull(
    predicate: (Char) -> Boolean
): Char?
Common
JVM
JS
Native
1.0

flatMap

Returns a single list of all elements yielded from results of transform function being invoked on each character of original char sequence.

fun <R> CharSequence.flatMap(
    transform: (Char) -> Iterable<R>
): List<R>
Common
JVM
JS
Native
1.4

flatMapIndexed

Returns a single list of all elements yielded from results of transform function being invoked on each character and its index in the original char sequence.

fun <R> CharSequence.flatMapIndexed(
    transform: (index: Int, Char) -> Iterable<R>
): List<R>
Common
JVM
JS
Native
1.4

flatMapIndexedTo

Appends all elements yielded from results of transform function being invoked on each character and its index in the original char sequence, to the given destination.

fun <R, C : MutableCollection<in R>> CharSequence.flatMapIndexedTo(
    destination: C,
    transform: (index: Int, Char) -> Iterable<R>
): C
Common
JVM
JS
Native
1.0

flatMapTo

Appends all elements yielded from results of transform function being invoked on each character of original char sequence, to the given destination.

fun <R, C : MutableCollection<in R>> CharSequence.flatMapTo(
    destination: C,
    transform: (Char) -> Iterable<R>
): C
Common
JVM
JS
Native
1.0

fold

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each character.

fun <R> CharSequence.fold(
    initial: R,
    operation: (acc: R, Char) -> R
): R
Common
JVM
JS
Native
1.0

foldIndexed

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each character with its index in the original char sequence.

fun <R> CharSequence.foldIndexed(
    initial: R,
    operation: (index: Int, acc: R, Char) -> R
): R
Common
JVM
JS
Native
1.0

foldRight

Accumulates value starting with initial value and applying operation from right to left to each character and current accumulator value.

fun <R> CharSequence.foldRight(
    initial: R,
    operation: (Char, acc: R) -> R
): R
Common
JVM
JS
Native
1.0

foldRightIndexed

Accumulates value starting with initial value and applying operation from right to left to each character with its index in the original char sequence and current accumulator value.

fun <R> CharSequence.foldRightIndexed(
    initial: R,
    operation: (index: Int, Char, acc: R) -> R
): R
Common
JVM
JS
Native
1.0

forEach

Performs the given action on each character.

fun CharSequence.forEach(action: (Char) -> Unit)
Common
JVM
JS
Native
1.0

forEachIndexed

Performs the given action on each character, providing sequential index with the character.

fun CharSequence.forEachIndexed(
    action: (index: Int, Char) -> Unit)
JVM
1.0

format

Uses this string as a format string and returns a string obtained by substituting format specifiers in the format string with the provided arguments, using the default locale.

fun String.format(vararg args: Any?): String

Uses this string as a format string and returns a string obtained by substituting format specifiers in the format string with the provided arguments, using the specified locale. If locale is null then no localization is applied.

fun String.format(locale: Locale?, vararg args: Any?): String

get

Returns a named group with the specified name.

JS
1.7
operator fun <ERROR CLASS>.get(name: String): MatchGroup?
Common
JVM
Native
1.2
operator fun MatchGroupCollection.get(
    name: String
): MatchGroup?
Common
JVM
JS
Native
1.0

getOrElse

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.

fun CharSequence.getOrElse(
    index: Int,
    defaultValue: (Int) -> Char
): Char
Common
JVM
JS
Native
1.0

getOrNull

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

fun CharSequence.getOrNull(index: Int): Char?
Common
JVM
JS
Native
1.0

groupBy

Groups characters of the original char sequence by the key returned by the given keySelector function applied to each character and returns a map where each group key is associated with a list of corresponding characters.

fun <K> CharSequence.groupBy(
    keySelector: (Char) -> K
): Map<K, List<Char>>

Groups values returned by the valueTransform function applied to each character of the original char sequence by the key returned by the given keySelector function applied to the character and returns a map where each group key is associated with a list of corresponding values.

fun <K, V> CharSequence.groupBy(
    keySelector: (Char) -> K,
    valueTransform: (Char) -> V
): Map<K, List<V>>
Common
JVM
JS
Native
1.0

groupByTo

Groups characters of the original char sequence by the key returned by the given keySelector function applied to each character and puts to the destination map each group key associated with a list of corresponding characters.

fun <K, M : MutableMap<in K, MutableList<Char>>> CharSequence.groupByTo(
    destination: M,
    keySelector: (Char) -> K
): M

Groups values returned by the valueTransform function applied to each character of the original char sequence by the key returned by the given keySelector function applied to the character and puts to the destination map each group key associated with a list of corresponding values.

fun <K, V, M : MutableMap<in K, MutableList<V>>> CharSequence.groupByTo(
    destination: M,
    keySelector: (Char) -> K,
    valueTransform: (Char) -> V
): M
Common
JVM
JS
Native
1.1

groupingBy

Creates a Grouping source from a char sequence to be used later with one of group-and-fold operations using the specified keySelector function to extract a key from each character.

fun <K> CharSequence.groupingBy(
    keySelector: (Char) -> K
): Grouping<Char, K>
Common
JVM
JS
Native
1.0

hasSurrogatePairAt

Returns true if this CharSequence has Unicode surrogate pair at the specified index.

fun CharSequence.hasSurrogatePairAt(index: Int): Boolean
Common
JVM
JS
Native
1.9

HexFormat

Builds a new HexFormat by configuring its format options using the specified builderAction, and returns the resulting format.

fun HexFormat(builderAction: Builder.() -> Unit): HexFormat
Common
JVM
JS
Native
1.9

hexToByte

Parses a Byte value from this string using the specified format.

fun String.hexToByte(
    format: HexFormat = HexFormat.Default
): Byte
Common
JVM
JS
Native
1.9

hexToByteArray

Parses a byte array from this string using the specified format.

fun String.hexToByteArray(
    format: HexFormat = HexFormat.Default
): ByteArray
Common
JVM
JS
Native
1.9

hexToInt

Parses an Int value from this string using the specified format.

fun String.hexToInt(
    format: HexFormat = HexFormat.Default
): Int
Common
JVM
JS
Native
1.9

hexToLong

Parses a Long value from this string using the specified format.

fun String.hexToLong(
    format: HexFormat = HexFormat.Default
): Long
Common
JVM
JS
Native
1.9

hexToShort

Parses a Short value from this string using the specified format.

fun String.hexToShort(
    format: HexFormat = HexFormat.Default
): Short
Common
JVM
JS
Native
1.9

hexToUByte

Parses an UByte value from this string using the specified format.

fun String.hexToUByte(
    format: HexFormat = HexFormat.Default
): UByte
Common
JVM
JS
Native
1.9

hexToUByteArray

Parses a byte array from this string using the specified format.

fun String.hexToUByteArray(
    format: HexFormat = HexFormat.Default
): UByteArray
Common
JVM
JS
Native
1.9

hexToUInt

Parses an UInt value from this string using the specified format.

fun String.hexToUInt(
    format: HexFormat = HexFormat.Default
): UInt
Common
JVM
JS
Native
1.9

hexToULong

Parses an ULong value from this string using the specified format.

fun String.hexToULong(
    format: HexFormat = HexFormat.Default
): ULong
Common
JVM
JS
Native
1.9

hexToUShort

Parses an UShort value from this string using the specified format.

fun String.hexToUShort(
    format: HexFormat = HexFormat.Default
): UShort
Common
JVM
JS
Native
1.3

ifBlank

Returns this char sequence if it is not empty and doesn't consist solely of whitespace characters, or the result of calling defaultValue function otherwise.

fun <C, R> C.ifBlank(
    defaultValue: () -> R
): R where C : CharSequence, C : R
Common
JVM
JS
Native
1.3

ifEmpty

Returns this char sequence if it's not empty or the result of calling defaultValue function if the char sequence is empty.

fun <C, R> C.ifEmpty(
    defaultValue: () -> R
): R where C : CharSequence, C : R
Common
JVM
JS
Native
1.0

indexOf

Returns the index within this string of the first occurrence of the specified character, starting from the specified startIndex.

fun CharSequence.indexOf(
    char: Char,
    startIndex: Int = 0,
    ignoreCase: Boolean = false
): Int

Returns the index within this char sequence of the first occurrence of the specified string, starting from the specified startIndex.

fun CharSequence.indexOf(
    string: String,
    startIndex: Int = 0,
    ignoreCase: Boolean = false
): Int
Common
JVM
JS
Native
1.0

indexOfAny

Finds the index of the first occurrence of any of the specified chars in this char sequence, starting from the specified startIndex and optionally ignoring the case.

fun CharSequence.indexOfAny(
    chars: CharArray,
    startIndex: Int = 0,
    ignoreCase: Boolean = false
): Int

Finds the index of the first occurrence of any of the specified strings in this char sequence, starting from the specified startIndex and optionally ignoring the case.

fun CharSequence.indexOfAny(
    strings: Collection<String>,
    startIndex: Int = 0,
    ignoreCase: Boolean = false
): Int
Common
JVM
JS
Native
1.0

indexOfFirst

Returns index of the first character matching the given predicate, or -1 if the char sequence does not contain such character.

fun CharSequence.indexOfFirst(
    predicate: (Char) -> Boolean
): Int
Common
JVM
JS
Native
1.0

indexOfLast

Returns index of the last character matching the given predicate, or -1 if the char sequence does not contain such character.

fun CharSequence.indexOfLast(
    predicate: (Char) -> Boolean
): Int

insert

Native
1.3

Inserts characters in a subsequence of the specified character sequence csq into this string builder at the specified index and returns this instance.

fun StringBuilder.insert(
    index: Int,
    csq: CharSequence?,
    start: Int,
    end: Int
): StringBuilder
Common
JS
Native
1.9

Inserts the string representation of the specified byte value into this string builder at the specified index and returns this instance.

fun StringBuilder.insert(
    index: Int,
    value: Byte
): StringBuilder
Common
JS
Native
1.9

Inserts the string representation of the specified short value into this string builder at the specified index and returns this instance.

fun StringBuilder.insert(
    index: Int,
    value: Short
): StringBuilder
Common
JS
Native
1.4

insertRange

Inserts characters in a subarray of the specified character array value into this string builder at the specified index and returns this instance.

fun StringBuilder.insertRange(
    index: Int,
    value: CharArray,
    startIndex: Int,
    endIndex: Int
): StringBuilder

Inserts characters in a subsequence of the specified character sequence value into this string builder at the specified index and returns this instance.

fun StringBuilder.insertRange(
    index: Int,
    value: CharSequence,
    startIndex: Int,
    endIndex: Int
): StringBuilder
JVM
1.0

intern

Returns a canonical representation for this string object.

fun String.intern(): String
Common
JVM
JS
Native
1.0

isBlank

Returns true if this char sequence is empty or consists solely of whitespace characters according to Char.isWhitespace.

fun CharSequence.isBlank(): Boolean
Common
JVM
JS
Native
1.0

isDefined

Returns true if this character (Unicode code point) is defined in Unicode.

fun Char.isDefined(): Boolean
Common
JVM
JS
Native
1.0

isDigit

Returns true if this character is a digit.

fun Char.isDigit(): Boolean
Common
JVM
JS
Native
1.0

isEmpty

Returns true if this char sequence is empty (contains no characters).

fun CharSequence.isEmpty(): Boolean
Common
JVM
JS
Native
1.0

isHighSurrogate

Returns true if this character is a Unicode high-surrogate code unit (also known as leading-surrogate code unit).

fun Char.isHighSurrogate(): Boolean
JVM
1.0

isIdentifierIgnorable

Returns true if this character (Unicode code point) should be regarded as an ignorable character in a Java identifier or a Unicode identifier.

fun Char.isIdentifierIgnorable(): Boolean
Common
JVM
JS
Native
1.0

isISOControl

Returns true if this character is an ISO control character.

fun Char.isISOControl(): Boolean
JVM
1.0

isJavaIdentifierPart

Returns true if this character (Unicode code point) may be part of a Java identifier as other than the first character.

fun Char.isJavaIdentifierPart(): Boolean
JVM
1.0

isJavaIdentifierStart

Returns true if this character is permissible as the first character in a Java identifier.

fun Char.isJavaIdentifierStart(): Boolean
Common
JVM
JS
Native
1.0

isLetter

Returns true if this character is a letter.

fun Char.isLetter(): Boolean
Common
JVM
JS
Native
1.0

isLetterOrDigit

Returns true if this character is a letter or digit.

fun Char.isLetterOrDigit(): Boolean
Common
JVM
JS
Native
1.0

isLowerCase

Returns true if this character is lower case.

fun Char.isLowerCase(): Boolean
Common
JVM
JS
Native
1.0

isLowSurrogate

Returns true if this character is a Unicode low-surrogate code unit (also known as trailing-surrogate code unit).

fun Char.isLowSurrogate(): Boolean
Common
JVM
JS
Native
1.0

isNotBlank

Returns true if this char sequence is not empty and contains some characters except whitespace characters.

fun CharSequence.isNotBlank(): Boolean
Common
JVM
JS
Native
1.0

isNotEmpty

Returns true if this char sequence is not empty.

fun CharSequence.isNotEmpty(): Boolean
Common
JVM
JS
Native
1.0

isNullOrBlank

Returns true if this nullable char sequence is either null or empty or consists solely of whitespace characters.

fun CharSequence?.isNullOrBlank(): Boolean
Common
JVM
JS
Native
1.0

isNullOrEmpty

Returns true if this nullable char sequence is either null or empty.

fun CharSequence?.isNullOrEmpty(): Boolean
Common
JVM
JS
Native
1.0

isSurrogate

Returns true if this character is a Unicode surrogate code unit.

fun Char.isSurrogate(): Boolean
Common
JVM
JS
Native
1.0

isTitleCase

Returns true if this character is a title case letter.

fun Char.isTitleCase(): Boolean
Common
JVM
JS
Native
1.0

isUpperCase

Returns true if this character is upper case.

fun Char.isUpperCase(): Boolean
Common
JVM
JS
Native
1.0

isWhitespace

Determines whether a character is whitespace.

fun Char.isWhitespace(): Boolean
Common
JVM
JS
Native
1.0

iterator

Iterator for characters of the given char sequence.

operator fun CharSequence.iterator(): CharIterator
Common
JVM
JS
Native
1.0

last

Returns the last character.

fun CharSequence.last(): Char

Returns the last character matching the given predicate.

fun CharSequence.last(predicate: (Char) -> Boolean): Char
Common
JVM
JS
Native
1.0

lastIndexOf

Returns the index within this char sequence of the last occurrence of the specified character, starting from the specified startIndex.

fun CharSequence.lastIndexOf(
    char: Char,
    startIndex: Int = lastIndex,
    ignoreCase: Boolean = false
): Int

Returns the index within this char sequence of the last occurrence of the specified string, starting from the specified startIndex.

fun CharSequence.lastIndexOf(
    string: String,
    startIndex: Int = lastIndex,
    ignoreCase: Boolean = false
): Int
Common
JVM
JS
Native
1.0

lastIndexOfAny

Finds the index of the last occurrence of any of the specified chars in this char sequence, starting from the specified startIndex and optionally ignoring the case.

fun CharSequence.lastIndexOfAny(
    chars: CharArray,
    startIndex: Int = lastIndex,
    ignoreCase: Boolean = false
): Int

Finds the index of the last occurrence of any of the specified strings in this char sequence, starting from the specified startIndex and optionally ignoring the case.

fun CharSequence.lastIndexOfAny(
    strings: Collection<String>,
    startIndex: Int = lastIndex,
    ignoreCase: Boolean = false
): Int
Common
JVM
JS
Native
1.0

lastOrNull

Returns the last character, or null if the char sequence is empty.

fun CharSequence.lastOrNull(): Char?

Returns the last character matching the given predicate, or null if no such character was found.

fun CharSequence.lastOrNull(
    predicate: (Char) -> Boolean
): Char?
Common
JVM
JS
Native
1.0

lines

Splits this char sequence to a list of lines delimited by any of the following character sequences: CRLF, LF or CR.

fun CharSequence.lines(): List<String>
Common
JVM
JS
Native
1.0

lineSequence

Splits this char sequence to a sequence of lines delimited by any of the following character sequences: CRLF, LF or CR.

fun CharSequence.lineSequence(): Sequence<String>

lowercase

JVM
1.5

Converts this character to lower case using Unicode mapping rules of the specified locale.

fun Char.lowercase(locale: Locale): String
JVM
1.5

Returns a copy of this string converted to lower case using the rules of the specified locale.

fun String.lowercase(locale: Locale): String
Common
JVM
JS
Native
1.5

Converts this character to lower case using Unicode mapping rules of the invariant locale.

fun Char.lowercase(): String
Common
JVM
JS
Native
1.5

Returns a copy of this string converted to lower case using Unicode mapping rules of the invariant locale.

fun String.lowercase(): String
Common
JVM
JS
Native
1.5

lowercaseChar

Converts this character to lower case using Unicode mapping rules of the invariant locale.

fun Char.lowercaseChar(): Char
Common
JVM
JS
Native
1.0

map

Returns a list containing the results of applying the given transform function to each character in the original char sequence.

fun <R> CharSequence.map(transform: (Char) -> R): List<R>
Common
JVM
JS
Native
1.0

mapIndexed

Returns a list containing the results of applying the given transform function to each character and its index in the original char sequence.

fun <R> CharSequence.mapIndexed(
    transform: (index: Int, Char) -> R
): List<R>
Common
JVM
JS
Native
1.0

mapIndexedNotNull

Returns a list containing only the non-null results of applying the given transform function to each character and its index in the original char sequence.

fun <R : Any> CharSequence.mapIndexedNotNull(
    transform: (index: Int, Char) -> R?
): List<R>
Common
JVM
JS
Native
1.0

mapIndexedNotNullTo

Applies the given transform function to each character and its index in the original char sequence and appends only the non-null results to the given destination.

fun <R : Any, C : MutableCollection<in R>> CharSequence.mapIndexedNotNullTo(
    destination: C,
    transform: (index: Int, Char) -> R?
): C
Common
JVM
JS
Native
1.0

mapIndexedTo

Applies the given transform function to each character and its index in the original char sequence and appends the results to the given destination.

fun <R, C : MutableCollection<in R>> CharSequence.mapIndexedTo(
    destination: C,
    transform: (index: Int, Char) -> R
): C
Common
JVM
JS
Native
1.0

mapNotNull

Returns a list containing only the non-null results of applying the given transform function to each character in the original char sequence.

fun <R : Any> CharSequence.mapNotNull(
    transform: (Char) -> R?
): List<R>
Common
JVM
JS
Native
1.0

mapNotNullTo

Applies the given transform function to each character in the original char sequence and appends only the non-null results to the given destination.

fun <R : Any, C : MutableCollection<in R>> CharSequence.mapNotNullTo(
    destination: C,
    transform: (Char) -> R?
): C
Common
JVM
JS
Native
1.0

mapTo

Applies the given transform function to each character of the original char sequence and appends the results to the given destination.

fun <R, C : MutableCollection<in R>> CharSequence.mapTo(
    destination: C,
    transform: (Char) -> R
): C
JS
1.1

match

fun String.match(regex: String): Array<String>?

matches

Common
JVM
JS
Native
1.0

Returns true if this char sequence matches the given regular expression.

infix fun CharSequence.matches(regex: Regex): Boolean
JS
1.1
fun String.matches(regex: String): Boolean

max

Returns the largest character.

Common
JS
Native
1.7
fun CharSequence.max(): Char
JVM
1.0
fun CharSequence.max(): Char?
Common
JVM
JS
Native
1.0

maxBy

Returns the first character yielding the largest value of the given function.

fun <R : Comparable<R>> any_iterable<R>.maxBy(
    selector: (Char) -> R
): Char
Common
JVM
JS
Native
1.4

maxByOrNull

Returns the first character yielding the largest value of the given function or null if there are no characters.

fun <R : Comparable<R>> CharSequence.maxByOrNull(
    selector: (Char) -> R
): Char?
Common
JVM
JS
Native
1.4

maxOf

Returns the largest value among all values produced by selector function applied to each character in the char sequence.

fun <R : Comparable<R>> any_iterable<R>.maxOf(
    selector: (Char) -> R
): R
Common
JVM
JS
Native
1.4

maxOfOrNull

Returns the largest value among all values produced by selector function applied to each character in the char sequence or null if there are no characters.

fun <R : Comparable<R>> any_iterable<R>.maxOfOrNull(
    selector: (Char) -> R
): R?
Common
JVM
JS
Native
1.4

maxOfWith

Returns the largest value according to the provided comparator among all values produced by selector function applied to each character in the char sequence.

fun <R> CharSequence.maxOfWith(
    comparator: Comparator<in R>,
    selector: (Char) -> R
): R
Common
JVM
JS
Native
1.4

maxOfWithOrNull

Returns the largest value according to the provided comparator among all values produced by selector function applied to each character in the char sequence or null if there are no characters.

fun <R> CharSequence.maxOfWithOrNull(
    comparator: Comparator<in R>,
    selector: (Char) -> R
): R?
Common
JVM
JS
Native
1.4

maxOrNull

Returns the largest character or null if there are no characters.

fun CharSequence.maxOrNull(): Char?

maxWith

Common
JVM
JS
Native
1.7

Returns the first character having the largest value according to the provided comparator.

fun CharSequence.maxWith(
    comparator: Comparator<in Char>
): Char
JVM
1.0
fun CharSequence.maxWith(
    comparator: Comparator<in Char>
): Char?
Common
JVM
JS
Native
1.4

maxWithOrNull

Returns the first character having the largest value according to the provided comparator or null if there are no characters.

fun CharSequence.maxWithOrNull(
    comparator: Comparator<in Char>
): Char?

min

Returns the smallest character.

Common
JS
Native
1.7
fun CharSequence.min(): Char
JVM
1.0
fun CharSequence.min(): Char?
Common
JVM
JS
Native
1.0

minBy

Returns the first character yielding the smallest value of the given function.

fun <R : Comparable<R>> any_iterable<R>.minBy(
    selector: (Char) -> R
): Char
Common
JVM
JS
Native
1.4

minByOrNull

Returns the first character yielding the smallest value of the given function or null if there are no characters.

fun <R : Comparable<R>> CharSequence.minByOrNull(
    selector: (Char) -> R
): Char?
Common
JVM
JS
Native
1.4

minOf

Returns the smallest value among all values produced by selector function applied to each character in the char sequence.

fun <R : Comparable<R>> any_iterable<R>.minOf(
    selector: (Char) -> R
): R
Common
JVM
JS
Native
1.4

minOfOrNull

Returns the smallest value among all values produced by selector function applied to each character in the char sequence or null if there are no characters.

fun <R : Comparable<R>> any_iterable<R>.minOfOrNull(
    selector: (Char) -> R
): R?
Common
JVM
JS
Native
1.4

minOfWith

Returns the smallest value according to the provided comparator among all values produced by selector function applied to each character in the char sequence.

fun <R> CharSequence.minOfWith(
    comparator: Comparator<in R>,
    selector: (Char) -> R
): R
Common
JVM
JS
Native
1.4

minOfWithOrNull

Returns the smallest value according to the provided comparator among all values produced by selector function applied to each character in the char sequence or null if there are no characters.

fun <R> CharSequence.minOfWithOrNull(
    comparator: Comparator<in R>,
    selector: (Char) -> R
): R?
Common
JVM
JS
Native
1.4

minOrNull

Returns the smallest character or null if there are no characters.

fun CharSequence.minOrNull(): Char?

minWith

Common
JVM
JS
Native
1.7

Returns the first character having the smallest value according to the provided comparator.

fun CharSequence.minWith(
    comparator: Comparator<in Char>
): Char
JVM
1.0
fun CharSequence.minWith(
    comparator: Comparator<in Char>
): Char?
Common
JVM
JS
Native
1.4

minWithOrNull

Returns the first character having the smallest value according to the provided comparator or null if there are no characters.

fun CharSequence.minWithOrNull(
    comparator: Comparator<in Char>
): Char?
Common
JVM
JS
Native
1.0

none

Returns true if the char sequence has no characters.

fun CharSequence.none(): Boolean

Returns true if no characters match the given predicate.

fun CharSequence.none(predicate: (Char) -> Boolean): Boolean
JVM
1.0

offsetByCodePoints

Returns the index within this string that is offset from the given index by codePointOffset code points.

fun String.offsetByCodePoints(
    index: Int,
    codePointOffset: Int
): Int
Common
JVM
JS
Native
1.1

onEach

Performs the given action on each character and returns the char sequence itself afterwards.

fun <S : CharSequence> S.onEach(action: (Char) -> Unit): S
Common
JVM
JS
Native
1.4

onEachIndexed

Performs the given action on each character, providing sequential index with the character, and returns the char sequence itself afterwards.

fun <S : CharSequence> S.onEachIndexed(
    action: (index: Int, Char) -> Unit
): S
Common
JVM
JS
Native
1.0

orEmpty

Returns the string if it is not null, or the empty string otherwise.

fun String?.orEmpty(): String
Common
JVM
JS
Native
1.0

padEnd

Returns a char sequence with content of this char sequence padded at the end to the specified length with the specified character or space.

fun CharSequence.padEnd(
    length: Int,
    padChar: Char = ' '
): CharSequence

Pads the string to the specified length at the end with the specified character or space.

fun String.padEnd(length: Int, padChar: Char = ' '): String
Common
JVM
JS
Native
1.0

padStart

Returns a char sequence with content of this char sequence padded at the beginning to the specified length with the specified character or space.

fun CharSequence.padStart(
    length: Int,
    padChar: Char = ' '
): CharSequence

Pads the string to the specified length at the beginning with the specified character or space.

fun String.padStart(length: Int, padChar: Char = ' '): String
Common
JVM
JS
Native
1.0

partition

Splits the original char sequence into pair of char sequences, where first char sequence contains characters for which predicate yielded true, while second char sequence contains characters for which predicate yielded false.

fun CharSequence.partition(
    predicate: (Char) -> Boolean
): Pair<CharSequence, CharSequence>

Splits the original string into pair of strings, where first string contains characters for which predicate yielded true, while second string contains characters for which predicate yielded false.

fun String.partition(
    predicate: (Char) -> Boolean
): Pair<String, String>
Common
JVM
JS
Native
1.0

plus

Concatenates this Char and a String.

operator fun Char.plus(other: String): String
Common
JVM
JS
Native
1.0

prependIndent

Prepends indent to every line of the original string.

fun String.prependIndent(indent: String = " "): String
Common
JVM
JS
Native
1.3

random

Returns a random character from this char sequence.

fun CharSequence.random(): Char

Returns a random character from this char sequence using the specified source of randomness.

fun CharSequence.random(random: Random): Char
Common
JVM
JS
Native
1.4

randomOrNull

Returns a random character from this char sequence, or null if this char sequence is empty.

fun CharSequence.randomOrNull(): Char?

Returns a random character from this char sequence using the specified source of randomness, or null if this char sequence is empty.

fun CharSequence.randomOrNull(random: Random): Char?
Common
JVM
JS
Native
1.0

reduce

Accumulates value starting with the first character and applying operation from left to right to current accumulator value and each character.

fun CharSequence.reduce(
    operation: (acc: Char, Char) -> Char
): Char
Common
JVM
JS
Native
1.0

reduceIndexed

Accumulates value starting with the first character and applying operation from left to right to current accumulator value and each character with its index in the original char sequence.

fun CharSequence.reduceIndexed(
    operation: (index: Int, acc: Char, Char) -> Char
): Char
Common
JVM
JS
Native
1.4

reduceIndexedOrNull

Accumulates value starting with the first character and applying operation from left to right to current accumulator value and each character with its index in the original char sequence.

fun CharSequence.reduceIndexedOrNull(
    operation: (index: Int, acc: Char, Char) -> Char
): Char?
Common
JVM
JS
Native
1.4

reduceOrNull

Accumulates value starting with the first character and applying operation from left to right to current accumulator value and each character.

fun CharSequence.reduceOrNull(
    operation: (acc: Char, Char) -> Char
): Char?
Common
JVM
JS
Native
1.0

reduceRight

Accumulates value starting with the last character and applying operation from right to left to each character and current accumulator value.

fun CharSequence.reduceRight(
    operation: (Char, acc: Char) -> Char
): Char
Common
JVM
JS
Native
1.0

reduceRightIndexed

Accumulates value starting with the last character and applying operation from right to left to each character with its index in the original char sequence and current accumulator value.

fun CharSequence.reduceRightIndexed(
    operation: (index: Int, Char, acc: Char) -> Char
): Char
Common
JVM
JS
Native
1.4

reduceRightIndexedOrNull

Accumulates value starting with the last character and applying operation from right to left to each character with its index in the original char sequence and current accumulator value.

fun CharSequence.reduceRightIndexedOrNull(
    operation: (index: Int, Char, acc: Char) -> Char
): Char?
Common
JVM
JS
Native
1.4

reduceRightOrNull

Accumulates value starting with the last character and applying operation from right to left to each character and current accumulator value.

fun CharSequence.reduceRightOrNull(
    operation: (Char, acc: Char) -> Char
): Char?
Common
JVM
JS
Native
1.0

regionMatches

Returns true if the specified range in this char sequence is equal to the specified range in another char sequence.

fun CharSequence.regionMatches(
    thisOffset: Int,
    other: CharSequence,
    otherOffset: Int,
    length: Int,
    ignoreCase: Boolean = false
): Boolean

Returns true if the specified range in this string is equal to the specified range in another string.

fun String.regionMatches(
    thisOffset: Int,
    other: String,
    otherOffset: Int,
    length: Int,
    ignoreCase: Boolean = false
): Boolean
Common
JVM
JS
Native
1.0

removePrefix

If this char sequence starts with the given prefix, returns a new char sequence with the prefix removed. Otherwise, returns a new char sequence with the same characters.

fun CharSequence.removePrefix(
    prefix: CharSequence
): CharSequence

If this string starts with the given prefix, returns a copy of this string with the prefix removed. Otherwise, returns this string.

fun String.removePrefix(prefix: CharSequence): String
Common
JVM
JS
Native
1.0

removeRange

Returns a char sequence with content of this char sequence where its part at the given range is removed.

fun CharSequence.removeRange(
    startIndex: Int,
    endIndex: Int
): CharSequence

Removes the part of a string at a given range.

fun String.removeRange(
    startIndex: Int,
    endIndex: Int
): String

Returns a char sequence with content of this char sequence where its part at the given range is removed.

fun CharSequence.removeRange(range: IntRange): CharSequence

Removes the part of a string at the given range.

fun String.removeRange(range: IntRange): String
Common
JVM
JS
Native
1.0

removeSuffix

If this char sequence ends with the given suffix, returns a new char sequence with the suffix removed. Otherwise, returns a new char sequence with the same characters.

fun CharSequence.removeSuffix(
    suffix: CharSequence
): CharSequence

If this string ends with the given suffix, returns a copy of this string with the suffix removed. Otherwise, returns this string.

fun String.removeSuffix(suffix: CharSequence): String
Common
JVM
JS
Native
1.0

removeSurrounding

When this char sequence starts with the given prefix and ends with the given suffix, returns a new char sequence having both the given prefix and suffix removed. Otherwise, returns a new char sequence with the same characters.

fun CharSequence.removeSurrounding(
    prefix: CharSequence,
    suffix: CharSequence
): CharSequence

Removes from a string both the given prefix and suffix if and only if it starts with the prefix and ends with the suffix. Otherwise, returns this string unchanged.

fun String.removeSurrounding(
    prefix: CharSequence,
    suffix: CharSequence
): String

When this char sequence starts with and ends with the given delimiter, returns a new char sequence having this delimiter removed both from the start and end. Otherwise, returns a new char sequence with the same characters.

fun CharSequence.removeSurrounding(
    delimiter: CharSequence
): CharSequence

Removes the given delimiter string from both the start and the end of this string if and only if it starts with and ends with the delimiter. Otherwise, returns this string unchanged.

fun String.removeSurrounding(delimiter: CharSequence): String
Common
JVM
JS
Native
1.0

repeat

Returns a string containing this char sequence repeated n times.

fun CharSequence.repeat(n: Int): String
Common
JVM
JS
Native
1.0

replace

Returns a new string obtained by replacing each substring of this char sequence that matches the given regular expression with the given replacement.

fun CharSequence.replace(
    regex: Regex,
    replacement: String
): String

Returns a new string obtained by replacing each substring of this char sequence that matches the given regular expression with the result of the given function transform that takes MatchResult and returns a string to be used as a replacement for that match.

fun CharSequence.replace(
    regex: Regex,
    transform: (MatchResult) -> CharSequence
): String

Returns a new string with all occurrences of oldChar replaced with newChar.

fun String.replace(
    oldChar: Char,
    newChar: Char,
    ignoreCase: Boolean = false
): String

Returns a new string obtained by replacing all occurrences of the oldValue substring in this string with the specified newValue string.

fun String.replace(
    oldValue: String,
    newValue: String,
    ignoreCase: Boolean = false
): String
Common
JVM
JS
Native
1.0

replaceAfter

Replace part of string after the first occurrence of given delimiter with the replacement string. If the string does not contain the delimiter, returns missingDelimiterValue which defaults to the original string.

fun String.replaceAfter(
    delimiter: Char,
    replacement: String,
    missingDelimiterValue: String = this
): String
fun String.replaceAfter(
    delimiter: String,
    replacement: String,
    missingDelimiterValue: String = this
): String
Common
JVM
JS
Native
1.0

replaceAfterLast

Replace part of string after the last occurrence of given delimiter with the replacement string. If the string does not contain the delimiter, returns missingDelimiterValue which defaults to the original string.

fun String.replaceAfterLast(
    delimiter: String,
    replacement: String,
    missingDelimiterValue: String = this
): String
fun String.replaceAfterLast(
    delimiter: Char,
    replacement: String,
    missingDelimiterValue: String = this
): String
Common
JVM
JS
Native
1.0

replaceBefore

Replace part of string before the first occurrence of given delimiter with the replacement string. If the string does not contain the delimiter, returns missingDelimiterValue which defaults to the original string.

fun String.replaceBefore(
    delimiter: Char,
    replacement: String,
    missingDelimiterValue: String = this
): String
fun String.replaceBefore(
    delimiter: String,
    replacement: String,
    missingDelimiterValue: String = this
): String
Common
JVM
JS
Native
1.0

replaceBeforeLast

Replace part of string before the last occurrence of given delimiter with the replacement string. If the string does not contain the delimiter, returns missingDelimiterValue which defaults to the original string.

fun String.replaceBeforeLast(
    delimiter: Char,
    replacement: String,
    missingDelimiterValue: String = this
): String
fun String.replaceBeforeLast(
    delimiter: String,
    replacement: String,
    missingDelimiterValue: String = this
): String
Common
JVM
JS
Native
1.0

replaceFirst

Replaces the first occurrence of the given regular expression regex in this char sequence with specified replacement expression.

fun CharSequence.replaceFirst(
    regex: Regex,
    replacement: String
): String

Returns a new string with the first occurrence of oldChar replaced with newChar.

fun String.replaceFirst(
    oldChar: Char,
    newChar: Char,
    ignoreCase: Boolean = false
): String

Returns a new string obtained by replacing the first occurrence of the oldValue substring in this string with the specified newValue string.

fun String.replaceFirst(
    oldValue: String,
    newValue: String,
    ignoreCase: Boolean = false
): String
Common
JVM
JS
Native
1.5

replaceFirstChar

Returns a copy of this string having its first character replaced with the result of the specified transform, or the original string if it's empty.

fun String.replaceFirstChar(
    transform: (Char) -> Char
): String
fun String.replaceFirstChar(
    transform: (Char) -> CharSequence
): String
Common
JVM
JS
Native
1.0

replaceIndent

Detects a common minimal indent like it does trimIndent and replaces it with the specified newIndent.

fun String.replaceIndent(newIndent: String = ""): String
Common
JVM
JS
Native
1.0

replaceIndentByMargin

Detects indent by marginPrefix as it does trimMargin and replace it with newIndent.

fun String.replaceIndentByMargin(
    newIndent: String = "",
    marginPrefix: String = "|"
): String
Common
JVM
JS
Native
1.0

replaceRange

Returns a char sequence with content of this char sequence where its part at the given range is replaced with the replacement char sequence.

fun CharSequence.replaceRange(
    startIndex: Int,
    endIndex: Int,
    replacement: CharSequence
): CharSequence

Replaces the part of the string at the given range with the replacement char sequence.

fun String.replaceRange(
    startIndex: Int,
    endIndex: Int,
    replacement: CharSequence
): String

Returns a char sequence with content of this char sequence where its part at the given range is replaced with the replacement char sequence.

fun CharSequence.replaceRange(
    range: IntRange,
    replacement: CharSequence
): CharSequence

Replace the part of string at the given range with the replacement string.

fun String.replaceRange(
    range: IntRange,
    replacement: CharSequence
): String
Common
JVM
JS
Native
1.0

reversed

Returns a char sequence with characters in reversed order.

fun CharSequence.reversed(): CharSequence

Returns a string with characters in reversed order.

fun String.reversed(): String
Common
JVM
JS
Native
1.4

runningFold

Returns a list containing successive accumulation values generated by applying operation from left to right to each character and current accumulator value that starts with initial value.

fun <R> CharSequence.runningFold(
    initial: R,
    operation: (acc: R, Char) -> R
): List<R>
Common
JVM
JS
Native
1.4

runningFoldIndexed

Returns a list containing successive accumulation values generated by applying operation from left to right to each character, its index in the original char sequence and current accumulator value that starts with initial value.

fun <R> CharSequence.runningFoldIndexed(
    initial: R,
    operation: (index: Int, acc: R, Char) -> R
): List<R>
Common
JVM
JS
Native
1.4

runningReduce

Returns a list containing successive accumulation values generated by applying operation from left to right to each character and current accumulator value that starts with the first character of this char sequence.

fun CharSequence.runningReduce(
    operation: (acc: Char, Char) -> Char
): List<Char>
Common
JVM
JS
Native
1.4

runningReduceIndexed

Returns a list containing successive accumulation values generated by applying operation from left to right to each character, its index in the original char sequence and current accumulator value that starts with the first character of this char sequence.

fun CharSequence.runningReduceIndexed(
    operation: (index: Int, acc: Char, Char) -> Char
): List<Char>
Common
JVM
JS
Native
1.4

scan

Returns a list containing successive accumulation values generated by applying operation from left to right to each character and current accumulator value that starts with initial value.

fun <R> CharSequence.scan(
    initial: R,
    operation: (acc: R, Char) -> R
): List<R>
Common
JVM
JS
Native
1.4

scanIndexed

Returns a list containing successive accumulation values generated by applying operation from left to right to each character, its index in the original char sequence and current accumulator value that starts with initial value.

fun <R> CharSequence.scanIndexed(
    initial: R,
    operation: (index: Int, acc: R, Char) -> R
): List<R>
Common
JS
Native
1.3

set

Sets the character at the specified index to the specified value.

operator fun StringBuilder.set(index: Int, value: Char)
Native
1.3

setCharAt

fun StringBuilder.setCharAt(index: Int, value: Char)
Common
JS
Native
1.4

setRange

Replaces characters in the specified range of this string builder with characters in the specified string value and returns this instance.

fun StringBuilder.setRange(
    startIndex: Int,
    endIndex: Int,
    value: String
): StringBuilder
Common
JVM
JS
Native
1.0

single

Returns the single character, or throws an exception if the char sequence is empty or has more than one character.

fun CharSequence.single(): Char

Returns the single character matching the given predicate, or throws exception if there is no or more than one matching character.

fun CharSequence.single(predicate: (Char) -> Boolean): Char
Common
JVM
JS
Native
1.0

singleOrNull

Returns single character, or null if the char sequence is empty or has more than one character.

fun CharSequence.singleOrNull(): Char?

Returns the single character matching the given predicate, or null if character was not found or more than one character was found.

fun CharSequence.singleOrNull(
    predicate: (Char) -> Boolean
): Char?
Common
JVM
JS
Native
1.0

slice

Returns a char sequence containing characters of the original char sequence at the specified range of indices.

fun CharSequence.slice(indices: IntRange): CharSequence

Returns a string containing characters of the original string at the specified range of indices.

fun String.slice(indices: IntRange): String

Returns a char sequence containing characters of the original char sequence at specified indices.

fun CharSequence.slice(indices: Iterable<Int>): CharSequence

Returns a string containing characters of the original string at specified indices.

fun String.slice(indices: Iterable<Int>): String

split

Common
JVM
JS
Native
1.0

Splits this char sequence to a list of strings around occurrences of the specified delimiters.

fun CharSequence.split(
    vararg delimiters: String,
    ignoreCase: Boolean = false,
    limit: Int = 0
): List<String>
fun CharSequence.split(
    vararg delimiters: Char,
    ignoreCase: Boolean = false,
    limit: Int = 0
): List<String>
Common
JVM
JS
Native
1.0

Splits this char sequence to a list of strings around matches of the given regular expression.

fun CharSequence.split(
    regex: Regex,
    limit: Int = 0
): List<String>
JVM
1.0

Splits this char sequence around matches of the given regular expression.

fun CharSequence.split(
    regex: Pattern,
    limit: Int = 0
): List<String>
Common
JVM
JS
Native
1.0

splitToSequence

Splits this char sequence to a sequence of strings around occurrences of the specified delimiters.

fun CharSequence.splitToSequence(
    vararg delimiters: String,
    ignoreCase: Boolean = false,
    limit: Int = 0
): Sequence<String>
fun CharSequence.splitToSequence(
    vararg delimiters: Char,
    ignoreCase: Boolean = false,
    limit: Int = 0
): Sequence<String>

Splits this char sequence to a sequence of strings around matches of the given regular expression.

fun CharSequence.splitToSequence(
    regex: Regex,
    limit: Int = 0
): Sequence<String>
Common
JVM
JS
Native
1.0

startsWith

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

fun CharSequence.startsWith(
    char: Char,
    ignoreCase: Boolean = false
): Boolean

Returns true if this char sequence starts with the specified prefix.

fun CharSequence.startsWith(
    prefix: CharSequence,
    ignoreCase: Boolean = false
): Boolean

Returns true if a substring of this char sequence starting at the specified offset startIndex starts with the specified prefix.

fun CharSequence.startsWith(
    prefix: CharSequence,
    startIndex: Int,
    ignoreCase: Boolean = false
): Boolean

Returns true if this string starts with the specified prefix.

fun String.startsWith(
    prefix: String,
    ignoreCase: Boolean = false
): Boolean

Returns true if a substring of this string starting at the specified offset startIndex starts with the specified prefix.

fun String.startsWith(
    prefix: String,
    startIndex: Int,
    ignoreCase: Boolean = false
): Boolean

String

Converts the data from a portion of the specified array of bytes to characters using the specified character set and returns the conversion result as a string.

JVM
1.0
fun String(
    bytes: ByteArray,
    offset: Int,
    length: Int,
    charset: Charset
): String

Converts the data from the specified array of bytes to characters using the specified character set and returns the conversion result as a string.

JVM
1.0
fun String(bytes: ByteArray, charset: Charset): String

Converts the data from a portion of the specified array of bytes to characters using the UTF-8 character set and returns the conversion result as a string.

JVM
1.0
fun String(
    bytes: ByteArray,
    offset: Int,
    length: Int
): String

Converts the data from the specified array of bytes to characters using the UTF-8 character set and returns the conversion result as a string.

JVM
1.0
fun String(bytes: ByteArray): String

Converts the code points from a portion of the specified Unicode code point array to a string.

JVM
1.0
fun String(
    codePoints: IntArray,
    offset: Int,
    length: Int
): String

Converts the contents of the specified StringBuffer to a string.

JVM
1.0
fun String(stringBuffer: StringBuffer): String

Converts the contents of the specified StringBuilder to a string.

JVM
1.0
fun String(stringBuilder: StringBuilder): String

Converts the characters in the specified array to a string.

Common
JS
Native
1.2
fun String(chars: CharArray): String
JVM
1.0
fun String(chars: CharArray): String

Converts the characters from a portion of the specified array to a string.

Common
JS
Native
1.2
fun String(
    chars: CharArray,
    offset: Int,
    length: Int
): String
JVM
1.0
fun String(
    chars: CharArray,
    offset: Int,
    length: Int
): String
Common
JVM
JS
Native
1.0

subSequence

Returns a subsequence of this char sequence specified by the given range of indices.

fun CharSequence.subSequence(range: IntRange): CharSequence

Returns a subsequence of this char sequence.

fun String.subSequence(start: Int, end: Int): CharSequence
Common
JVM
JS
Native
1.0

substring

Returns a substring specified by the given range of indices.

fun String.substring(range: IntRange): String

Returns a substring of chars from a range of this char sequence starting at the startIndex and ending right before the endIndex.

fun CharSequence.substring(
    startIndex: Int,
    endIndex: Int = length
): String

Returns a substring of chars at indices from the specified range of this char sequence.

fun CharSequence.substring(range: IntRange): String

Returns a substring of this string that starts at the specified startIndex and continues to the end of the string.

fun String.substring(startIndex: Int): String

Returns the substring of this string starting at the startIndex and ending right before the endIndex.

fun String.substring(startIndex: Int, endIndex: Int): String
Common
JVM
JS
Native
1.0

substringAfter

Returns a substring after the first occurrence of delimiter. If the string does not contain the delimiter, returns missingDelimiterValue which defaults to the original string.

fun String.substringAfter(
    delimiter: Char,
    missingDelimiterValue: String = this
): String
fun String.substringAfter(
    delimiter: String,
    missingDelimiterValue: String = this
): String
Common
JVM
JS
Native
1.0

substringAfterLast

Returns a substring after the last occurrence of delimiter. If the string does not contain the delimiter, returns missingDelimiterValue which defaults to the original string.

fun String.substringAfterLast(
    delimiter: Char,
    missingDelimiterValue: String = this
): String
fun String.substringAfterLast(
    delimiter: String,
    missingDelimiterValue: String = this
): String
Common
JVM
JS
Native
1.0

substringBefore

Returns a substring before the first occurrence of delimiter. If the string does not contain the delimiter, returns missingDelimiterValue which defaults to the original string.

fun String.substringBefore(
    delimiter: Char,
    missingDelimiterValue: String = this
): String
fun String.substringBefore(
    delimiter: String,
    missingDelimiterValue: String = this
): String
Common
JVM
JS
Native
1.0

substringBeforeLast

Returns a substring before the last occurrence of delimiter. If the string does not contain the delimiter, returns missingDelimiterValue which defaults to the original string.

fun String.substringBeforeLast(
    delimiter: Char,
    missingDelimiterValue: String = this
): String
fun String.substringBeforeLast(
    delimiter: String,
    missingDelimiterValue: String = this
): String
Common
JVM
JS
Native
1.0

sumBy

Returns the sum of all values produced by selector function applied to each character in the char sequence.

fun CharSequence.sumBy(selector: (Char) -> Int): Int
Common
JVM
JS
Native
1.0

sumByDouble

Returns the sum of all values produced by selector function applied to each character in the char sequence.

fun CharSequence.sumByDouble(
    selector: (Char) -> Double
): Double

sumOf

Returns the sum of all values produced by selector function applied to each character in the char sequence.

Common
JVM
JS
Native
1.4
fun CharSequence.sumOf(selector: (Char) -> Double): Double
Common
JVM
JS
Native
1.4
fun CharSequence.sumOf(selector: (Char) -> Int): Int
Common
JVM
JS
Native
1.4
fun CharSequence.sumOf(selector: (Char) -> Long): Long
Common
JVM
JS
Native
1.5
fun CharSequence.sumOf(selector: (Char) -> UInt): UInt
Common
JVM
JS
Native
1.5
fun CharSequence.sumOf(selector: (Char) -> ULong): ULong
JVM
1.4
fun CharSequence.sumOf(
    selector: (Char) -> BigDecimal
): BigDecimal
JVM
1.4
fun CharSequence.sumOf(
    selector: (Char) -> BigInteger
): BigInteger
Common
JVM
JS
Native
1.0

take

Returns a subsequence of this char sequence containing the first n characters from this char sequence, or the entire char sequence if this char sequence is shorter.

fun CharSequence.take(n: Int): CharSequence

Returns a string containing the first n characters from this string, or the entire string if this string is shorter.

fun String.take(n: Int): String
Common
JVM
JS
Native
1.0

takeLast

Returns a subsequence of this char sequence containing the last n characters from this char sequence, or the entire char sequence if this char sequence is shorter.

fun CharSequence.takeLast(n: Int): CharSequence

Returns a string containing the last n characters from this string, or the entire string if this string is shorter.

fun String.takeLast(n: Int): String
Common
JVM
JS
Native
1.0

takeLastWhile

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

fun CharSequence.takeLastWhile(
    predicate: (Char) -> Boolean
): CharSequence

Returns a string containing last characters that satisfy the given predicate.

fun String.takeLastWhile(
    predicate: (Char) -> Boolean
): String
Common
JVM
JS
Native
1.0

takeWhile

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

fun CharSequence.takeWhile(
    predicate: (Char) -> Boolean
): CharSequence

Returns a string containing the first characters that satisfy the given predicate.

fun String.takeWhile(predicate: (Char) -> Boolean): String

titlecase

Common
JVM
JS
Native
1.5

Converts this character to title case using Unicode mapping rules of the invariant locale.

fun Char.titlecase(): String
JVM
1.5

Converts this character to title case using Unicode mapping rules of the specified locale.

fun Char.titlecase(locale: Locale): String
Common
JVM
JS
Native
1.5

titlecaseChar

Converts this character to title case using Unicode mapping rules of the invariant locale.

fun Char.titlecaseChar(): Char
JVM
1.2

toBigDecimal

Parses the string as a java.math.BigDecimal number and returns the result.

fun String.toBigDecimal(): BigDecimal
fun String.toBigDecimal(mathContext: MathContext): BigDecimal
JVM
1.2

toBigDecimalOrNull

Parses the string as a java.math.BigDecimal number and returns the result or null if the string is not a valid representation of a number.

fun String.toBigDecimalOrNull(): BigDecimal?
fun String.toBigDecimalOrNull(
    mathContext: MathContext
): BigDecimal?
JVM
1.2

toBigInteger

Parses the string as a java.math.BigInteger number and returns the result.

fun String.toBigInteger(): BigInteger
fun String.toBigInteger(radix: Int): BigInteger
JVM
1.2

toBigIntegerOrNull

Parses the string as a java.math.BigInteger number and returns the result or null if the string is not a valid representation of a number.

fun String.toBigIntegerOrNull(): BigInteger?
fun String.toBigIntegerOrNull(radix: Int): BigInteger?
Common
JVM
JS
Native
1.4

toBoolean

Returns true if this string is not null and its content is equal to the word "true", ignoring case, and false otherwise.

fun String?.toBoolean(): Boolean
Common
JVM
JS
Native
1.5

toBooleanStrict

Returns true if the content of this string is equal to the word "true", false if it is equal to "false", and throws an exception otherwise.

fun String.toBooleanStrict(): Boolean
Common
JVM
JS
Native
1.5

toBooleanStrictOrNull

Returns true if the content of this string is equal to the word "true", false if it is equal to "false", and null otherwise.

fun String.toBooleanStrictOrNull(): Boolean?
Common
JVM
JS
Native
1.0

toByte

Parses the string as a signed Byte number and returns the result.

fun String.toByte(): Byte
fun String.toByte(radix: Int): Byte
JVM
1.0

toByteArray

Encodes the contents of this string using the specified character set and returns the resulting byte array.

fun String.toByteArray(
    charset: Charset = Charsets.UTF_8
): ByteArray
Common
JVM
JS
Native
1.1

toByteOrNull

Parses the string as a signed Byte number and returns the result or null if the string is not a valid representation of a number.

fun String.toByteOrNull(): Byte?
fun String.toByteOrNull(radix: Int): Byte?

toCharArray

Common
JVM
JS
Native
1.0

Returns a CharArray containing characters of this string.

fun String.toCharArray(): CharArray
Common
JVM
JS
Native
1.3

Returns a CharArray containing characters of this string or its substring.

fun String.toCharArray(
    startIndex: Int = 0,
    endIndex: Int = this.length
): CharArray
Common
JVM
JS
Native
1.0

Copies characters from this string into the destination character array and returns that array.

fun String.toCharArray(
    destination: CharArray,
    destinationOffset: Int = 0,
    startIndex: Int = 0,
    endIndex: Int = length
): CharArray
Common
JS
Native
1.4

Copies characters from this string builder into the destination character array.

fun StringBuilder.toCharArray(
    destination: CharArray,
    destinationOffset: Int = 0,
    startIndex: Int = 0,
    endIndex: Int = this.length)
Common
JVM
JS
Native
1.0

toCollection

Appends all characters to the given destination collection.

fun <C : MutableCollection<in Char>> CharSequence.toCollection(
    destination: C
): C
Common
JVM
JS
Native
1.0

toDouble

Parses the string as a Double number and returns the result.

fun String.toDouble(): Double
Common
JVM
JS
Native
1.0

toDoubleOrNull

Parses the string as a Double number and returns the result or null if the string is not a valid representation of a number.

fun String.toDoubleOrNull(): Double?
Common
JVM
JS
Native
1.0

toFloat

Parses the string as a Float number and returns the result.

fun String.toFloat(): Float
Common
JVM
JS
Native
1.0

toFloatOrNull

Parses the string as a Float number and returns the result or null if the string is not a valid representation of a number.

fun String.toFloatOrNull(): Float?
Common
JVM
JS
Native
1.0

toHashSet

Returns a new HashSet of all characters.

fun CharSequence.toHashSet(): HashSet<Char>
Common
JVM
JS
Native
1.9

toHexString

Formats bytes in this array using the specified format.

fun ByteArray.toHexString(
    format: HexFormat = HexFormat.Default
): String
fun ByteArray.toHexString(
    startIndex: Int = 0,
    endIndex: Int = size,
    format: HexFormat = HexFormat.Default
): String
fun UByteArray.toHexString(
    format: HexFormat = HexFormat.Default
): String
fun UByteArray.toHexString(
    startIndex: Int = 0,
    endIndex: Int = size,
    format: HexFormat = HexFormat.Default
): String

Formats this Byte value using the specified format.

fun Byte.toHexString(
    format: HexFormat = HexFormat.Default
): String

Formats this Short value using the specified format.

fun Short.toHexString(
    format: HexFormat = HexFormat.Default
): String

Formats this Int value using the specified format.

fun Int.toHexString(
    format: HexFormat = HexFormat.Default
): String

Formats this Long value using the specified format.

fun Long.toHexString(
    format: HexFormat = HexFormat.Default
): String

Formats this UByte value using the specified format.

fun UByte.toHexString(
    format: HexFormat = HexFormat.Default
): String

Formats this UShort value using the specified format.

fun UShort.toHexString(
    format: HexFormat = HexFormat.Default
): String

Formats this UInt value using the specified format.

fun UInt.toHexString(
    format: HexFormat = HexFormat.Default
): String

Formats this ULong value using the specified format.

fun ULong.toHexString(
    format: HexFormat = HexFormat.Default
): String
Common
JVM
JS
Native
1.0

toInt

Parses the string as an Int number and returns the result.

fun String.toInt(): Int
fun String.toInt(radix: Int): Int
Common
JVM
JS
Native
1.1

toIntOrNull

Parses the string as an Int number and returns the result or null if the string is not a valid representation of a number.

fun String.toIntOrNull(): Int?
fun String.toIntOrNull(radix: Int): Int?
Common
JVM
JS
Native
1.0

toList

Returns a List containing all characters.

fun CharSequence.toList(): List<Char>
Common
JVM
JS
Native
1.0

toLong

Parses the string as a Long number and returns the result.

fun String.toLong(): Long
fun String.toLong(radix: Int): Long
Common
JVM
JS
Native
1.1

toLongOrNull

Parses the string as a Long number and returns the result or null if the string is not a valid representation of a number.

fun String.toLongOrNull(): Long?
fun String.toLongOrNull(radix: Int): Long?

toLowerCase

JVM
1.0

Returns a copy of this string converted to lower case using the rules of the specified locale.

fun String.toLowerCase(locale: Locale): String
Common
JVM
JS
Native
1.0

Converts this character to lower case using Unicode mapping rules of the invariant locale.

fun Char.toLowerCase(): Char
Common
JVM
JS
Native
1.0

Returns a copy of this string converted to lower case using the rules of the default locale.

fun String.toLowerCase(): String
Common
JVM
JS
Native
1.0

toMutableList

Returns a new MutableList filled with all characters of this char sequence.

fun CharSequence.toMutableList(): MutableList<Char>
JVM
1.0

toPattern

Converts the string into a regular expression Pattern optionally with the specified flags from Pattern or'd together so that strings can be split or matched on.

fun String.toPattern(flags: Int = 0): Pattern
Common
JVM
JS
Native
1.0

toRegex

Converts the string into a regular expression Regex with the default options.

fun String.toRegex(): Regex

Converts the string into a regular expression Regex with the specified single option.

fun String.toRegex(option: RegexOption): Regex

Converts the string into a regular expression Regex with the specified set of options.

fun String.toRegex(options: Set<RegexOption>): Regex
Common
JVM
JS
Native
1.0

toSet

Returns a Set of all characters.

fun CharSequence.toSet(): Set<Char>
Common
JVM
JS
Native
1.0

toShort

Parses the string as a Short number and returns the result.

fun String.toShort(): Short
fun String.toShort(radix: Int): Short
Common
JVM
JS
Native
1.1

toShortOrNull

Parses the string as a Short number and returns the result or null if the string is not a valid representation of a number.

fun String.toShortOrNull(): Short?
fun String.toShortOrNull(radix: Int): Short?
JVM
1.0

toSortedSet

Returns a new SortedSet of all characters.

fun CharSequence.toSortedSet(): SortedSet<Char>
Common
JVM
JS
Native
1.1

toString

Returns a string representation of this Byte value in the specified radix.

fun UByte.toString(radix: Int): String
fun Byte.toString(radix: Int): String

Returns a string representation of this Short value in the specified radix.

fun UShort.toString(radix: Int): String
fun Short.toString(radix: Int): String

Returns a string representation of this Int value in the specified radix.

fun UInt.toString(radix: Int): String
fun Int.toString(radix: Int): String

Returns a string representation of this Long value in the specified radix.

fun ULong.toString(radix: Int): String
fun Long.toString(radix: Int): String
JVM
1.0

toTitleCase

Converts this character to title case using Unicode mapping rules of the invariant locale.

fun Char.toTitleCase(): Char
Common
JVM
JS
Native
1.5

toUByte

Parses the string as a signed UByte number and returns the result.

fun String.toUByte(): UByte
fun String.toUByte(radix: Int): UByte
Common
JVM
JS
Native
1.5

toUByteOrNull

Parses the string as an UByte number and returns the result or null if the string is not a valid representation of a number.

fun String.toUByteOrNull(): UByte?
fun String.toUByteOrNull(radix: Int): UByte?
Common
JVM
JS
Native
1.5

toUInt

Parses the string as an UInt number and returns the result.

fun String.toUInt(): UInt
fun String.toUInt(radix: Int): UInt
Common
JVM
JS
Native
1.5

toUIntOrNull

Parses the string as an UInt number and returns the result or null if the string is not a valid representation of a number.

fun String.toUIntOrNull(): UInt?
fun String.toUIntOrNull(radix: Int): UInt?
Common
JVM
JS
Native
1.5

toULong

Parses the string as a ULong number and returns the result.

fun String.toULong(): ULong
fun String.toULong(radix: Int): ULong
Common
JVM
JS
Native
1.5

toULongOrNull

Parses the string as an ULong number and returns the result or null if the string is not a valid representation of a number.

fun String.toULongOrNull(): ULong?
fun String.toULongOrNull(radix: Int): ULong?

toUpperCase

JVM
1.0

Returns a copy of this string converted to upper case using the rules of the specified locale.

fun String.toUpperCase(locale: Locale): String
Common
JVM
JS
Native
1.0

Converts this character to upper case using Unicode mapping rules of the invariant locale.

fun Char.toUpperCase(): Char
Common
JVM
JS
Native
1.0

Returns a copy of this string converted to upper case using the rules of the default locale.

fun String.toUpperCase(): String
Common
JVM
JS
Native
1.5

toUShort

Parses the string as a UShort number and returns the result.

fun String.toUShort(): UShort
fun String.toUShort(radix: Int): UShort
Common
JVM
JS
Native
1.5

toUShortOrNull

Parses the string as an UShort number and returns the result or null if the string is not a valid representation of a number.

fun String.toUShortOrNull(): UShort?
fun String.toUShortOrNull(radix: Int): UShort?
Common
JVM
JS
Native
1.0

trim

Returns a subsequence of this char sequence having leading and trailing characters matching the predicate removed.

fun CharSequence.trim(
    predicate: (Char) -> Boolean
): CharSequence

Returns a string having leading and trailing characters matching the predicate removed.

fun String.trim(predicate: (Char) -> Boolean): String

Returns a subsequence of this char sequence having leading and trailing characters from the chars array removed.

fun CharSequence.trim(vararg chars: Char): CharSequence

Returns a string having leading and trailing characters from the chars array removed.

fun String.trim(vararg chars: Char): String

Returns a subsequence of this char sequence having leading and trailing whitespace removed.

Returns a string having leading and trailing whitespace removed.

fun String.trim(): String
Common
JVM
JS
Native
1.0

trimEnd

Returns a subsequence of this char sequence having trailing characters matching the predicate removed.

fun CharSequence.trimEnd(
    predicate: (Char) -> Boolean
): CharSequence

Returns a string having trailing characters matching the predicate removed.

fun String.trimEnd(predicate: (Char) -> Boolean): String

Returns a subsequence of this char sequence having trailing characters from the chars array removed.

fun CharSequence.trimEnd(vararg chars: Char): CharSequence

Returns a string having trailing characters from the chars array removed.

fun String.trimEnd(vararg chars: Char): String

Returns a subsequence of this char sequence having trailing whitespace removed.

fun CharSequence.trimEnd(): CharSequence

Returns a string having trailing whitespace removed.

fun String.trimEnd(): String
Common
JVM
JS
Native
1.0

trimIndent

Detects a common minimal indent of all the input lines, removes it from every line and also removes the first and the last lines if they are blank (notice difference blank vs empty).

fun String.trimIndent(): String
Common
JVM
JS
Native
1.0

trimMargin

Trims leading whitespace characters followed by marginPrefix from every line of a source string and removes the first and the last lines if they are blank (notice difference blank vs empty).

fun String.trimMargin(marginPrefix: String = "|"): String
Common
JVM
JS
Native
1.0

trimStart

Returns a subsequence of this char sequence having leading characters matching the predicate removed.

fun CharSequence.trimStart(
    predicate: (Char) -> Boolean
): CharSequence

Returns a string having leading characters matching the predicate removed.

fun String.trimStart(predicate: (Char) -> Boolean): String

Returns a subsequence of this char sequence having leading characters from the chars array removed.

fun CharSequence.trimStart(vararg chars: Char): CharSequence

Returns a string having leading characters from the chars array removed.

fun String.trimStart(vararg chars: Char): String

Returns a subsequence of this char sequence having leading whitespace removed.

fun CharSequence.trimStart(): CharSequence

Returns a string having leading whitespace removed.

fun String.trimStart(): String

uppercase

JVM
1.5

Converts this character to upper case using Unicode mapping rules of the specified locale.

fun Char.uppercase(locale: Locale): String
JVM
1.5

Returns a copy of this string converted to upper case using the rules of the specified locale.

fun String.uppercase(locale: Locale): String
Common
JVM
JS
Native
1.5

Converts this character to upper case using Unicode mapping rules of the invariant locale.

fun Char.uppercase(): String
Common
JVM
JS
Native
1.5

Returns a copy of this string converted to upper case using Unicode mapping rules of the invariant locale.

fun String.uppercase(): String
Common
JVM
JS
Native
1.5

uppercaseChar

Converts this character to upper case using Unicode mapping rules of the invariant locale.

fun Char.uppercaseChar(): Char
Common
JVM
JS
Native
1.2

windowed

Returns a list of snapshots of the window of the given size sliding along this char sequence with the given step, where each snapshot is a string.

fun CharSequence.windowed(
    size: Int,
    step: Int = 1,
    partialWindows: Boolean = false
): List<String>

Returns a list of results of applying the given transform function to an each char sequence representing a view over the window of the given size sliding along this char sequence with the given step.

fun <R> CharSequence.windowed(
    size: Int,
    step: Int = 1,
    partialWindows: Boolean = false,
    transform: (CharSequence) -> R
): List<R>
Common
JVM
JS
Native
1.2

windowedSequence

Returns a sequence of snapshots of the window of the given size sliding along this char sequence with the given step, where each snapshot is a string.

fun CharSequence.windowedSequence(
    size: Int,
    step: Int = 1,
    partialWindows: Boolean = false
): Sequence<String>

Returns a sequence of results of applying the given transform function to an each char sequence representing a view over the window of the given size sliding along this char sequence with the given step.

fun <R> CharSequence.windowedSequence(
    size: Int,
    step: Int = 1,
    partialWindows: Boolean = false,
    transform: (CharSequence) -> R
): Sequence<R>
Common
JVM
JS
Native
1.0

withIndex

Returns a lazy Iterable that wraps each character of the original char sequence into an IndexedValue containing the index of that character and the character itself.

fun CharSequence.withIndex(): Iterable<IndexedValue<Char>>
Common
JVM
JS
Native
1.0

zip

Returns a list of pairs built from the characters of this and the other char sequences with the same index The returned list has length of the shortest char sequence.

infix fun CharSequence.zip(
    other: CharSequence
): List<Pair<Char, Char>>

Returns a list of values built from the characters of this and the other char sequences with the same index using the provided transform function applied to each pair of characters. The returned list has length of the shortest char sequence.

fun <V> CharSequence.zip(
    other: CharSequence,
    transform: (a: Char, b: Char) -> V
): List<V>
Common
JVM
JS
Native
1.2

zipWithNext

Returns a list of pairs of each two adjacent characters in this char sequence.

fun CharSequence.zipWithNext(): List<Pair<Char, Char>>

Returns a list containing the results of applying the given transform function to an each pair of two adjacent characters in this char sequence.

fun <R> CharSequence.zipWithNext(
    transform: (a: Char, b: Char) -> R
): List<R>

Companion Object Properties

Common
JVM
JS
Native
1.0

CASE_INSENSITIVE_ORDER

A Comparator that orders strings ignoring character case.

val String.Companion.CASE_INSENSITIVE_ORDER: Comparator<String>

Companion Object Functions

JVM
1.0

format

Uses the provided format as a format string and returns a string obtained by substituting format specifiers in the format string with the provided arguments, using the default locale.

fun String.Companion.format(
    format: String,
    vararg args: Any?
): String

Uses the provided format as a format string and returns a string obtained by substituting format specifiers in the format string with the provided arguments, using the specified locale. If locale is null then no localization is applied.

fun String.Companion.format(
    locale: Locale?,
    format: String,
    vararg args: Any?
): String
Native
1.3

isSupplementaryCodePoint

Checks if the codepoint specified is a supplementary codepoint or not.

fun Char.Companion.isSupplementaryCodePoint(
    codepoint: Int
): Boolean
Native
1.3

isSurrogatePair

Checks if the specified high and low chars are Char.isHighSurrogate and Char.isLowSurrogate correspondingly.

fun Char.Companion.isSurrogatePair(
    high: Char,
    low: Char
): Boolean
Native
1.3

toChars

Converts the codepoint specified to a char array. If the codepoint is not supplementary, the method will return an array with one element otherwise it will return an array A with a high surrogate in A0 and a low surrogate in A1.

fun Char.Companion.toChars(codePoint: Int): CharArray
Native
1.3

toCodePoint

Converts a surrogate pair to a unicode code point. Doesn't validate that the characters are a valid surrogate pair.

fun Char.Companion.toCodePoint(high: Char, low: Char): Int