Package kotlin.text
Functions for working with text and regular expressions.
Types
Appendable
An object to which char sequences and values can be appended.
interface Appendabletypealias Appendable = AppendableCharCategory
Represents the character general category in the Unicode specification.
enum class CharCategoryCharDirectionality
Represents the Unicode directionality of a character. Character directionality is used to calculate the visual ordering of text.
enum class CharDirectionalityCharsets
Constant definitions for the standard charsets. These charsets are guaranteed to be available on every implementation of the Java platform.
object CharsetsMatchGroup
Represents the results from a single capturing group within a MatchResult of Regex.
class MatchGroupdata class MatchGroupMatchGroupCollection
Represents a collection of captured groups in a single match of a regular expression.
interface MatchGroupCollection : Collection<MatchGroup?>MatchNamedGroupCollection
Extends MatchGroupCollection by introducing a way to get matched groups by name, when regex supports it.
interface MatchNamedGroupCollection : MatchGroupCollectionMatchResult
Represents the results from a single regular expression match.
interface MatchResultRegex
Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.
class Regexclass Regex : SerializableRegexOption
Provides enumeration values to use to set regular expression options.
enum class RegexOptionenum class RegexOption : FlagEnumStringBuilder
A mutable sequence of characters.
class StringBuilder : Appendable, CharSequencetypealias StringBuilder = StringBuilderclass StringBuilder : CharSequence, AppendableTypography
Defines names for Unicode symbols used in proper Typography.
object TypographyExceptions
CharacterCodingException
The exception thrown when a character encoding or decoding error occurs.
open class CharacterCodingException : Exceptiontypealias CharacterCodingException = CharacterCodingExceptionExtensions for External Classes
Properties
category
Returns a value indicating a character's general category.
val Char.category: CharCategorydirectionality
Returns the Unicode directionality property for the given character.
val Char.directionality: CharDirectionalityindices
Returns the range of valid character indices for this char sequence.
val CharSequence.indices: IntRangelastIndex
Returns the index of the last character in the char sequence or -1 if it is empty.
val CharSequence.lastIndex: IntFunctions
all
Returns true if all characters match the given predicate.
fun CharSequence.all(predicate: (Char) -> Boolean): Booleanany
Returns true if char sequence has at least one character.
fun CharSequence.any(): BooleanReturns true if at least one character matches the given predicate.
fun CharSequence.any(predicate: (Char) -> Boolean): Booleanappend
Appends all arguments to the given Appendable.
fun <T : Appendable> T.append(vararg value: CharSequence?): Tfun StringBuilder.append(obj: Any?): StringBuilderfun StringBuilder.append(it: Boolean): StringBuilderfun StringBuilder.append(it: Byte): StringBuilderfun StringBuilder.append(it: Short): StringBuilderfun StringBuilder.append(it: Int): StringBuilderfun StringBuilder.append(it: Long): StringBuilderfun StringBuilder.append(it: Float): StringBuilderfun StringBuilder.append(it: Double): StringBuilderfun StringBuilder.append(it: String): StringBuilderfun StringBuilder.append(it: CharArray): StringBuilderAppends all arguments to the given StringBuilder.
fun StringBuilder.append(
vararg value: String?
): StringBuilderfun StringBuilder.append(vararg value: Any?): StringBuilderappendln
fun StringBuilder.appendln(it: String): StringBuilderfun StringBuilder.appendln(it: Boolean): StringBuilderfun StringBuilder.appendln(it: Byte): StringBuilderfun StringBuilder.appendln(it: Short): StringBuilderfun StringBuilder.appendln(it: Int): StringBuilderfun StringBuilder.appendln(it: Long): StringBuilderfun StringBuilder.appendln(it: Float): StringBuilderfun StringBuilder.appendln(it: Double): StringBuilderfun StringBuilder.appendln(it: Any?): StringBuilderfun StringBuilder.appendln(): StringBuilderappendRange
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
): TAppends 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
): StringBuilderAppends 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
): StringBuilderasIterable
Creates an Iterable instance that wraps the original char sequence returning its characters when being iterated.
fun CharSequence.asIterable(): Iterable<Char>asSequence
Creates a Sequence instance that wraps the original char sequence returning its characters when being iterated.
fun CharSequence.asSequence(): Sequence<Char>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>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>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
): MPopulates 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
): MassociateTo
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>
): MassociateWith
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>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
): MbuildString
Builds new string by populating newly created StringBuilder using provided builderAction and then converting it to String.
fun buildString(
builderAction: StringBuilder.() -> Unit
): StringBuilds 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
): Stringcapitalize
Returns a copy of this string having its first letter titlecased preferring Char.toTitleCase (if different from Char.toUpperCase) or by String.toUpperCase using the specified locale, or the original string, if it's empty or already starts with an upper case letter.
fun String.capitalize(locale: Locale): StringReturns a copy of this string having its first letter uppercased, or the original string, if it's empty or already starts with an upper case letter.
fun String.capitalize(): Stringcharset
Returns a named charset with the given charsetName name.
fun charset(charsetName: String): Charsetchunked
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>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>clear
Clears the content of this string builder making it empty and returns this instance.
fun StringBuilder.clear(): StringBuildercodePointAt
Returns the character (Unicode code point) at the specified index.
fun String.codePointAt(index: Int): IntcodePointBefore
Returns the character (Unicode code point) before the specified index.
fun String.codePointBefore(index: Int): IntcodePointCount
Returns the number of Unicode code points in the specified text range of this String.
fun String.codePointCount(
beginIndex: Int,
endIndex: Int
): IntcommonPrefixWith
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
): StringcommonSuffixWith
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
): StringcompareTo
Compares two strings lexicographically, optionally ignoring case differences.
fun String.compareTo(
other: String,
ignoreCase: Boolean = false
): Intfun String.compareTo(other: String, ignoreCase: Boolean): Intconcat
fun String.concat(str: String): Stringcontains
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
): BooleanReturns true if this char sequence contains the specified character char.
operator fun CharSequence.contains(
char: Char,
ignoreCase: Boolean = false
): BooleanReturns true if this char sequence contains at least one match of the specified regular expression regex.
operator fun CharSequence.contains(regex: Regex): BooleancontentEquals
Returns true if this string is equal to the contents of the specified CharSequence, false otherwise.
fun String.contentEquals(charSequence: CharSequence): BooleanReturns true if this string is equal to the contents of the specified StringBuffer, false otherwise.
fun String.contentEquals(
stringBuilder: StringBuffer
): Booleancount
Returns the length of this char sequence.
fun CharSequence.count(): IntReturns the number of characters matching the given predicate.
fun CharSequence.count(predicate: (Char) -> Boolean): Intdecapitalize
Returns a copy of this string having its first letter lowercased using the specified locale, or the original string, if it's empty or already starts with a lower case letter.
fun String.decapitalize(locale: Locale): StringReturns a copy of this string having its first letter lowercased, or the original string, if it's empty or already starts with a lower case letter.
fun String.decapitalize(): StringdecodeToString
Decodes a string from the bytes in UTF-8 encoding in this array.
fun ByteArray.decodeToString(): StringDecodes 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
): Stringfun ByteArray.decodeToString(
startIndex: Int,
endIndex: Int,
throwOnInvalidSequence: Boolean
): StringdeleteAt
Removes the character at the specified index from this string builder and returns this instance.
fun StringBuilder.deleteAt(index: Int): StringBuilderdeleteCharAt
Removes the character at the specified index from this string builder and returns this instance.
fun StringBuilder.deleteCharAt(index: Int): StringBuilderdeleteRange
Removes characters in the specified range from this string builder and returns this instance.
fun StringBuilder.deleteRange(
startIndex: Int,
endIndex: Int
): StringBuilderdrop
Returns a subsequence of this char sequence with the first n characters removed.
fun CharSequence.drop(n: Int): CharSequenceReturns a string with the first n characters removed.
fun String.drop(n: Int): StringdropLast
Returns a subsequence of this char sequence with the last n characters removed.
fun CharSequence.dropLast(n: Int): CharSequenceReturns a string with the last n characters removed.
fun String.dropLast(n: Int): StringdropLastWhile
Returns a subsequence of this char sequence containing all characters except last characters that satisfy the given predicate.
fun CharSequence.dropLastWhile(
predicate: (Char) -> Boolean
): CharSequenceReturns a string containing all characters except last characters that satisfy the given predicate.
fun String.dropLastWhile(
predicate: (Char) -> Boolean
): StringdropWhile
Returns a subsequence of this char sequence containing all characters except first characters that satisfy the given predicate.
fun CharSequence.dropWhile(
predicate: (Char) -> Boolean
): CharSequenceReturns a string containing all characters except first characters that satisfy the given predicate.
fun String.dropWhile(predicate: (Char) -> Boolean): StringelementAt
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): CharelementAtOrElse
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
): CharelementAtOrNull
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?encodeToByteArray
Encodes this string to an array of bytes in UTF-8 encoding.
fun String.encodeToByteArray(): ByteArrayEncodes 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
): ByteArrayfun String.encodeToByteArray(
startIndex: Int,
endIndex: Int,
throwOnInvalidSequence: Boolean
): ByteArrayendsWith
Returns true if this char sequence ends with the specified character.
fun CharSequence.endsWith(
char: Char,
ignoreCase: Boolean = false
): BooleanReturns true if this char sequence ends with the specified suffix.
fun CharSequence.endsWith(
suffix: CharSequence,
ignoreCase: Boolean = false
): BooleanReturns true if this string ends with the specified suffix.
fun String.endsWith(
suffix: String,
ignoreCase: Boolean = false
): Booleanfun String.endsWith(
suffix: String,
ignoreCase: Boolean
): BooleanensureCapacity
fun StringBuilder.ensureCapacity(capacity: Int)equals
Returns true if this character is equal to the other character, optionally ignoring character case.
fun Char.equals(
other: Char,
ignoreCase: Boolean = false
): BooleanReturns true if this string is equal to other, optionally ignoring character case.
fun String?.equals(
other: String?,
ignoreCase: Boolean = false
): Booleanfun String?.equals(
other: String?,
ignoreCase: Boolean
): Booleanfilter
Returns a char sequence containing only those characters from the original char sequence that match the given predicate.
fun CharSequence.filter(
predicate: (Char) -> Boolean
): CharSequenceReturns a string containing only those characters from the original string that match the given predicate.
fun String.filter(predicate: (Char) -> Boolean): StringfilterIndexed
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
): CharSequenceReturns a string containing only those characters from the original string that match the given predicate.
fun String.filterIndexed(
predicate: (index: Int, Char) -> Boolean
): StringfilterIndexedTo
Appends all characters matching the given predicate to the given destination.
fun <C : Appendable> CharSequence.filterIndexedTo(
destination: C,
predicate: (index: Int, Char) -> Boolean
): CfilterNot
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
): CharSequenceReturns a string containing only those characters from the original string that do not match the given predicate.
fun String.filterNot(predicate: (Char) -> Boolean): StringfilterNotTo
Appends all characters not matching the given predicate to the given destination.
fun <C : Appendable> CharSequence.filterNotTo(
destination: C,
predicate: (Char) -> Boolean
): CfilterTo
Appends all characters matching the given predicate to the given destination.
fun <C : Appendable> CharSequence.filterTo(
destination: C,
predicate: (Char) -> Boolean
): Cfind
Returns the first character matching the given predicate, or null if no such character was found.
fun CharSequence.find(predicate: (Char) -> Boolean): Char?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>?findLast
Returns the last character matching the given predicate, or null if no such character was found.
fun CharSequence.findLast(
predicate: (Char) -> Boolean
): Char?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>?first
Returns first character.
fun CharSequence.first(): CharReturns the first character matching the given predicate.
fun CharSequence.first(predicate: (Char) -> Boolean): CharfirstOrNull
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?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>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>
): Cfold
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
): RfoldIndexed
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
): RfoldRight
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
): RfoldRightIndexed
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
): RforEach
Performs the given action on each character.
fun CharSequence.forEach(action: (Char) -> Unit)forEachIndexed
Performs the given action on each character, providing sequential index with the character.
fun CharSequence.forEachIndexed(
action: (index: Int, Char) -> Unit)format
Uses this string as a format string and returns a string obtained by substituting the specified arguments, using the default locale.
fun String.format(vararg args: Any?): StringUses this string as a format string and returns a string obtained by substituting the specified arguments, using the specified locale.
fun String.format(locale: Locale, vararg args: Any?): Stringget
Returns a named group with the specified name.
operator fun MatchGroupCollection.get(
name: String
): MatchGroup?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
): ChargetOrNull
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?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>>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
): MGroups 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
): MgroupingBy
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>hasSurrogatePairAt
Returns true if this CharSequence has Unicode surrogate pair at the specified index.
fun CharSequence.hasSurrogatePairAt(index: Int): BooleanifBlank
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 : RifEmpty
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 : RindexOf
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
): IntReturns 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
): IntindexOfAny
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
): IntFinds 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
): IntindexOfFirst
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
): IntindexOfLast
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
): Intinsert
fun StringBuilder.insert(index: Int, c: Char): StringBuilderfun StringBuilder.insert(
index: Int,
chars: CharArray
): StringBuilderfun StringBuilder.insert(
index: Int,
csq: CharSequence?
): StringBuilderfun StringBuilder.insert(
index: Int,
string: String
): StringBuilderInserts 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
): StringBuilderinsertRange
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
): StringBuilderInserts 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
): StringBuilderintern
Returns a canonical representation for this string object.
fun String.intern(): StringisBlank
Returns true if this string is empty or consists solely of whitespace characters.
fun CharSequence.isBlank(): BooleanisDefined
Returns true if this character (Unicode code point) is defined in Unicode.
fun Char.isDefined(): BooleanisDigit
Returns true if this character (Unicode code point) is a digit.
fun Char.isDigit(): BooleanisEmpty
Returns true if this char sequence is empty (contains no characters).
fun CharSequence.isEmpty(): BooleanisHighSurrogate
Returns true if this character is a Unicode high-surrogate code unit (also known as leading-surrogate code unit).
fun Char.isHighSurrogate(): BooleanisIdentifierIgnorable
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(): BooleanisISOControl
Returns true if this character is an ISO control character.
fun Char.isISOControl(): BooleanisJavaIdentifierPart
Returns true if this character (Unicode code point) may be part of a Java identifier as other than the first character.
fun Char.isJavaIdentifierPart(): BooleanisJavaIdentifierStart
Returns true if this character is permissible as the first character in a Java identifier.
fun Char.isJavaIdentifierStart(): BooleanisLetter
Returns true if this character is a letter.
fun Char.isLetter(): BooleanisLetterOrDigit
Returns true if this character is a letter or digit.
fun Char.isLetterOrDigit(): BooleanisLowerCase
Returns true if this character is lower case.
fun Char.isLowerCase(): BooleanisLowSurrogate
Returns true if this character is a Unicode low-surrogate code unit (also known as trailing-surrogate code unit).
fun Char.isLowSurrogate(): BooleanisNotBlank
Returns true if this char sequence is not empty and contains some characters except of whitespace characters.
fun CharSequence.isNotBlank(): BooleanisNotEmpty
Returns true if this char sequence is not empty.
fun CharSequence.isNotEmpty(): BooleanisNullOrBlank
Returns true if this nullable char sequence is either null or empty or consists solely of whitespace characters.
fun CharSequence?.isNullOrBlank(): BooleanisNullOrEmpty
Returns true if this nullable char sequence is either null or empty.
fun CharSequence?.isNullOrEmpty(): BooleanisSurrogate
Returns true if this character is a Unicode surrogate code unit.
fun Char.isSurrogate(): BooleanisTitleCase
Returns true if this character is a titlecase character.
fun Char.isTitleCase(): BooleanisUpperCase
Returns true if this character is upper case.
fun Char.isUpperCase(): BooleanisWhitespace
Determines whether a character is whitespace according to the Unicode standard.
Returns true if the character is whitespace.
fun Char.isWhitespace(): Booleaniterator
Iterator for characters of the given char sequence.
operator fun CharSequence.iterator(): CharIteratorlast
Returns the last character.
fun CharSequence.last(): CharReturns the last character matching the given predicate.
fun CharSequence.last(predicate: (Char) -> Boolean): CharlastIndexOf
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
): IntReturns 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
): IntlastIndexOfAny
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
): IntFinds 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
): IntlastOrNull
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?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>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>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>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>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>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?
): CmapIndexedTo
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
): CmapNotNull
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>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?
): CmapTo
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
): Cmatch
fun String.match(regex: String): Array<String>?matches
Returns true if this char sequence matches the given regular expression.
infix fun CharSequence.matches(regex: Regex): Booleanfun String.matches(regex: String): Booleanmax
Returns the largest character or null if there are no characters.
fun CharSequence.max(): Char?maxBy
Returns the first character yielding the largest value of the given function or null if there are no characters.
fun <R : Comparable<R>> CharSequence.maxBy(
selector: (Char) -> R
): Char?maxWith
Returns the first character having the largest value according to the provided comparator or null if there are no characters.
fun CharSequence.maxWith(
comparator: Comparator<in Char>
): Char?min
Returns the smallest character or null if there are no characters.
fun CharSequence.min(): Char?minBy
Returns the first character yielding the smallest value of the given function or null if there are no characters.
fun <R : Comparable<R>> CharSequence.minBy(
selector: (Char) -> R
): Char?minWith
Returns the first character having the smallest value according to the provided comparator or null if there are no characters.
fun CharSequence.minWith(
comparator: Comparator<in Char>
): Char?none
Returns true if the char sequence has no characters.
fun CharSequence.none(): BooleanReturns true if no characters match the given predicate.
fun CharSequence.none(predicate: (Char) -> Boolean): BooleanoffsetByCodePoints
Returns the index within this string that is offset from the given index by codePointOffset code points.
fun String.offsetByCodePoints(
index: Int,
codePointOffset: Int
): IntonEach
Performs the given action on each character and returns the char sequence itself afterwards.
fun <S : CharSequence> S.onEach(action: (Char) -> Unit): SorEmpty
Returns the string if it is not null, or the empty string otherwise.
fun String?.orEmpty(): StringpadEnd
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 = ' '
): CharSequencePads the string to the specified length at the end with the specified character or space.
fun String.padEnd(length: Int, padChar: Char = ' '): StringpadStart
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 = ' '
): CharSequencePads the string to the specified length at the beginning with the specified character or space.
fun String.padStart(length: Int, padChar: Char = ' '): Stringpartition
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>plus
Concatenates this Char and a String.
operator fun Char.plus(other: String): StringprependIndent
Prepends indent to every line of the original string.
fun String.prependIndent(indent: String = " "): Stringrandom
Returns a random character from this char sequence.
fun CharSequence.random(): CharReturns a random character from this char sequence using the specified source of randomness.
fun CharSequence.random(random: Random): CharrandomOrNull
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?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
): CharreduceIndexed
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
): CharreduceOrNull
Accumulates value starting with the first character and applying operation from left to right to current accumulator value and each character. Returns null if the char sequence is empty.
fun CharSequence.reduceOrNull(
operation: (acc: Char, Char) -> Char
): Char?reduceRight
Accumulates value starting with last character and applying operation from right to left to each character and current accumulator value.
fun CharSequence.reduceRight(
operation: (Char, acc: Char) -> Char
): CharreduceRightIndexed
Accumulates value starting with 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
): CharreduceRightOrNull
Accumulates value starting with last character and applying operation from right to left to each character and current accumulator value. Returns null if the char sequence is empty.
fun CharSequence.reduceRightOrNull(
operation: (Char, acc: Char) -> Char
): Char?Regex_0
Creates a regular expression from the specified pattern string and the specified single option.
fun Regex_0(pattern: String, option: RegexOption): RegexregionMatches
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
): Booleanfun CharSequence.regionMatches(
thisOffset: Int,
other: CharSequence,
otherOffset: Int,
length: Int,
ignoreCase: Boolean
): BooleanReturns 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
): BooleanremovePrefix
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
): CharSequenceIf 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): StringremoveRange
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
): CharSequenceRemoves the part of a string at a given range.
fun String.removeRange(
startIndex: Int,
endIndex: Int
): StringReturns a char sequence with content of this char sequence where its part at the given range is removed.
fun CharSequence.removeRange(range: IntRange): CharSequenceremoveSuffix
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
): CharSequenceIf 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): StringremoveSurrounding
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
): CharSequenceRemoves 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
): StringWhen 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
): CharSequenceRemoves 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): Stringrepeat
Returns a string containing this char sequence repeated n times.
fun CharSequence.repeat(n: Int): Stringreplace
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
): StringReturns 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
): StringReturns a new string with all occurrences of oldChar replaced with newChar.
fun String.replace(
oldChar: Char,
newChar: Char,
ignoreCase: Boolean = false
): Stringfun String.replace(
oldChar: Char,
newChar: Char,
ignoreCase: Boolean
): StringReturns 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
): Stringfun String.replace(
oldValue: String,
newValue: String,
ignoreCase: Boolean
): StringreplaceAfter
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
): Stringfun String.replaceAfter(
delimiter: String,
replacement: String,
missingDelimiterValue: String = this
): StringreplaceAfterLast
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
): Stringfun String.replaceAfterLast(
delimiter: Char,
replacement: String,
missingDelimiterValue: String = this
): StringreplaceBefore
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
): Stringfun String.replaceBefore(
delimiter: String,
replacement: String,
missingDelimiterValue: String = this
): StringreplaceBeforeLast
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
): Stringfun String.replaceBeforeLast(
delimiter: String,
replacement: String,
missingDelimiterValue: String = this
): StringreplaceFirst
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
): StringReturns a new string with the first occurrence of oldChar replaced with newChar.
fun String.replaceFirst(
oldChar: Char,
newChar: Char,
ignoreCase: Boolean = false
): Stringfun String.replaceFirst(
oldChar: Char,
newChar: Char,
ignoreCase: Boolean
): StringReturns 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
): Stringfun String.replaceFirst(
oldValue: String,
newValue: String,
ignoreCase: Boolean
): StringreplaceIndent
Detects a common minimal indent like it does trimIndent and replaces it with the specified newIndent.
fun String.replaceIndent(newIndent: String = ""): StringreplaceIndentByMargin
Detects indent by marginPrefix as it does trimMargin and replace it with newIndent.
fun String.replaceIndentByMargin(
newIndent: String = "",
marginPrefix: String = "|"
): StringreplaceRange
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
): CharSequenceReplaces the part of the string at the given range with the replacement char sequence.
fun String.replaceRange(
startIndex: Int,
endIndex: Int,
replacement: CharSequence
): StringReturns 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
): CharSequenceReplace the part of string at the given range with the replacement string.
fun String.replaceRange(
range: IntRange,
replacement: CharSequence
): Stringreversed
Returns a char sequence with characters in reversed order.
fun CharSequence.reversed(): CharSequenceReturns a string with characters in reversed order.
fun String.reversed(): Stringscan
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>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>scanReduce
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.scanReduce(
operation: (acc: Char, Char) -> Char
): List<Char>scanReduceIndexed
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.scanReduceIndexed(
operation: (index: Int, acc: Char, Char) -> Char
): List<Char>set
Sets the character at the specified index to the specified value.
operator fun StringBuilder.set(index: Int, value: Char)setCharAt
fun StringBuilder.setCharAt(index: Int, value: Char)setLength
fun StringBuilder.setLength(l: Int)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
): StringBuildersingle
Returns the single character, or throws an exception if the char sequence is empty or has more than one character.
fun CharSequence.single(): CharReturns 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): CharsingleOrNull
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?slice
Returns a char sequence containing characters of the original char sequence at the specified range of indices.
fun CharSequence.slice(indices: IntRange): CharSequenceReturns a string containing characters of the original string at the specified range of indices.
fun String.slice(indices: IntRange): StringReturns a char sequence containing characters of the original char sequence at specified indices.
fun CharSequence.slice(indices: Iterable<Int>): CharSequencesplit
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>Splits this char sequence around matches of the given regular expression.
fun CharSequence.split(
regex: Regex,
limit: Int = 0
): List<String>fun CharSequence.split(
regex: Pattern,
limit: Int = 0
): List<String>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>startsWith
Returns true if this char sequence starts with the specified character.
fun CharSequence.startsWith(
char: Char,
ignoreCase: Boolean = false
): BooleanReturns true if this char sequence starts with the specified prefix.
fun CharSequence.startsWith(
prefix: CharSequence,
ignoreCase: Boolean = false
): BooleanReturns 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
): BooleanReturns true if this string starts with the specified prefix.
fun String.startsWith(
prefix: String,
ignoreCase: Boolean = false
): Booleanfun String.startsWith(
prefix: String,
ignoreCase: Boolean
): BooleanReturns 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
): Booleanfun String.startsWith(
prefix: String,
startIndex: Int,
ignoreCase: Boolean
): BooleanString
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.
Converts the data from the specified array of bytes to characters using the specified character set and returns the conversion result as a 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.
fun String(
bytes: ByteArray,
offset: Int,
length: Int
): StringConverts the data from the specified array of bytes to characters using the UTF-8 character set and returns the conversion result as a string.
fun String(bytes: ByteArray): StringConverts the code points from a portion of the specified Unicode code point array to a string.
fun String(
codePoints: IntArray,
offset: Int,
length: Int
): StringConverts the contents of the specified StringBuffer to a string.
fun String(stringBuffer: StringBuffer): StringConverts the contents of the specified StringBuilder to a string.
fun String(stringBuilder: StringBuilder): StringConverts the characters in the specified array to a string.
fun String(chars: CharArray): StringConverts the characters from a portion of the specified array to a string.
fun String(
chars: CharArray,
offset: Int,
length: Int
): StringsubSequence
Returns a subsequence of this char sequence specified by the given range of indices.
fun CharSequence.subSequence(range: IntRange): CharSequenceReturns a subsequence of this char sequence.
fun String.subSequence(start: Int, end: Int): CharSequencesubstring
Returns a substring specified by the given range of indices.
fun String.substring(range: IntRange): StringReturns 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
): StringReturns a substring of chars at indices from the specified range of this char sequence.
fun CharSequence.substring(range: IntRange): StringReturns a substring of this string that starts at the specified startIndex and continues to the end of the string.
fun String.substring(startIndex: Int): StringReturns the substring of this string starting at the startIndex and ending right before the endIndex.
fun String.substring(startIndex: Int, endIndex: Int): StringsubstringAfter
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
): Stringfun String.substringAfter(
delimiter: String,
missingDelimiterValue: String = this
): StringsubstringAfterLast
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
): Stringfun String.substringAfterLast(
delimiter: String,
missingDelimiterValue: String = this
): StringsubstringBefore
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
): Stringfun String.substringBefore(
delimiter: String,
missingDelimiterValue: String = this
): StringsubstringBeforeLast
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
): Stringfun String.substringBeforeLast(
delimiter: String,
missingDelimiterValue: String = this
): StringsumBy
Returns the sum of all values produced by selector function applied to each character in the char sequence.
fun CharSequence.sumBy(selector: (Char) -> Int): IntsumByDouble
Returns the sum of all values produced by selector function applied to each character in the char sequence.
fun CharSequence.sumByDouble(
selector: (Char) -> Double
): Doubletake
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): CharSequenceReturns a string containing the first n characters from this string, or the entire string if this string is shorter.
fun String.take(n: Int): StringtakeLast
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): CharSequenceReturns a string containing the last n characters from this string, or the entire string if this string is shorter.
fun String.takeLast(n: Int): StringtakeLastWhile
Returns a subsequence of this char sequence containing last characters that satisfy the given predicate.
fun CharSequence.takeLastWhile(
predicate: (Char) -> Boolean
): CharSequenceReturns a string containing last characters that satisfy the given predicate.
fun String.takeLastWhile(
predicate: (Char) -> Boolean
): StringtakeWhile
Returns a subsequence of this char sequence containing the first characters that satisfy the given predicate.
fun CharSequence.takeWhile(
predicate: (Char) -> Boolean
): CharSequenceReturns a string containing the first characters that satisfy the given predicate.
fun String.takeWhile(predicate: (Char) -> Boolean): StringtoBigDecimal
Parses the string as a java.math.BigDecimal number and returns the result.
fun String.toBigDecimal(): BigDecimalfun String.toBigDecimal(mathContext: MathContext): BigDecimaltoBigDecimalOrNull
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?toBigInteger
Parses the string as a java.math.BigInteger number and returns the result.
fun String.toBigInteger(): BigIntegerfun String.toBigInteger(radix: Int): BigIntegertoBigIntegerOrNull
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?toBoolean
Returns true if the contents of this string is equal to the word "true", ignoring case, and false otherwise.
fun String.toBoolean(): BooleantoByte
Parses the string as a signed Byte number and returns the result.
fun String.toByte(): Bytefun String.toByte(radix: Int): BytetoByteOrNull
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
Copies characters from this string into the destination character array and returns that array.
Returns a CharArray containing characters of this string or its substring.
fun String.toCharArray(
startIndex: Int = 0,
endIndex: Int = this.length
): CharArrayfun String.toCharArray(
startIndex: Int,
endIndex: Int
): CharArrayCopies 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)toCollection
Appends all characters to the given destination collection.
fun <C : MutableCollection<in Char>> CharSequence.toCollection(
destination: C
): CtoDoubleOrNull
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?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?toHashSet
Returns a HashSet of all characters.
fun CharSequence.toHashSet(): HashSet<Char>toInt
Parses the string as an Int number and returns the result.
fun String.toInt(): Intfun String.toInt(radix: Int): InttoIntOrNull
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?toList
Returns a List containing all characters.
fun CharSequence.toList(): List<Char>toLong
Parses the string as a Long number and returns the result.
fun String.toLong(): Longfun String.toLong(radix: Int): LongtoLongOrNull
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
Returns a copy of this string converted to lower case using the rules of the specified locale.
fun String.toLowerCase(locale: Locale): StringConverts this character to lowercase.
fun Char.toLowerCase(): CharReturns a copy of this string converted to lower case using the rules of the default locale.
fun String.toLowerCase(): StringtoMutableList
Returns a MutableList filled with all characters of this char sequence.
fun CharSequence.toMutableList(): MutableList<Char>toRegex
Converts the string into a regular expression Regex with the default options.
fun String.toRegex(): RegexConverts the string into a regular expression Regex with the specified single option.
fun String.toRegex(option: RegexOption): RegexConverts the string into a regular expression Regex with the specified set of options.
fun String.toRegex(options: Set<RegexOption>): RegextoSet
Returns a Set of all characters.
fun CharSequence.toSet(): Set<Char>toShort
Parses the string as a Short number and returns the result.
fun String.toShort(): Shortfun String.toShort(radix: Int): ShorttoShortOrNull
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?toSortedSet
Returns a SortedSet of all characters.
fun CharSequence.toSortedSet(): SortedSet<Char>toString
Returns a string representation of this Byte value in the specified radix.
fun UByte.toString(radix: Int): Stringfun Byte.toString(radix: Int): StringReturns a string representation of this Short value in the specified radix.
fun UShort.toString(radix: Int): Stringfun Short.toString(radix: Int): StringtoTitleCase
Converts this character to titlecase.
fun Char.toTitleCase(): ChartoUpperCase
Returns a copy of this string converted to upper case using the rules of the specified locale.
fun String.toUpperCase(locale: Locale): StringConverts this character to uppercase.
fun Char.toUpperCase(): CharReturns a copy of this string converted to upper case using the rules of the default locale.
fun String.toUpperCase(): Stringtrim
Returns a sub sequence of this char sequence having leading and trailing characters matching the predicate removed.
fun CharSequence.trim(
predicate: (Char) -> Boolean
): CharSequenceReturns a string having leading and trailing characters matching the predicate removed.
fun String.trim(predicate: (Char) -> Boolean): StringReturns a sub sequence of this char sequence having leading and trailing characters from the chars array removed.
fun CharSequence.trim(vararg chars: Char): CharSequenceReturns a string having leading and trailing characters from the chars array removed.
fun String.trim(vararg chars: Char): StringReturns a sub sequence of this char sequence having leading and trailing whitespace removed.
fun CharSequence.trim(): CharSequenceReturns a string having leading and trailing whitespace removed.
fun String.trim(): StringtrimEnd
Returns a sub sequence of this char sequence having trailing characters matching the predicate removed.
fun CharSequence.trimEnd(
predicate: (Char) -> Boolean
): CharSequenceReturns a string having trailing characters matching the predicate removed.
fun String.trimEnd(predicate: (Char) -> Boolean): StringReturns a sub sequence of this char sequence having trailing characters from the chars array removed.
fun CharSequence.trimEnd(vararg chars: Char): CharSequenceReturns a string having trailing characters from the chars array removed.
fun String.trimEnd(vararg chars: Char): StringReturns a sub sequence of this char sequence having trailing whitespace removed.
fun CharSequence.trimEnd(): CharSequenceReturns a string having trailing whitespace removed.
fun String.trimEnd(): StringtrimIndent
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(): StringtrimMargin
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 = "|"): StringtrimStart
Returns a sub sequence of this char sequence having leading characters matching the predicate removed.
fun CharSequence.trimStart(
predicate: (Char) -> Boolean
): CharSequenceReturns a string having leading characters matching the predicate removed.
fun String.trimStart(predicate: (Char) -> Boolean): StringReturns a sub sequence of this char sequence having leading characters from the chars array removed.
fun CharSequence.trimStart(vararg chars: Char): CharSequenceReturns a string having leading characters from the chars array removed.
fun String.trimStart(vararg chars: Char): StringReturns a sub sequence of this char sequence having leading whitespace removed.
fun CharSequence.trimStart(): CharSequenceReturns a string having leading whitespace removed.
fun String.trimStart(): Stringwindowed
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>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>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>>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>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
CASE_INSENSITIVE_ORDER
A Comparator that orders strings ignoring character case.
val String.Companion.CASE_INSENSITIVE_ORDER: Comparator<String>Companion Object Functions
format
Uses the provided format as a format string and returns a string obtained by substituting the specified arguments, using the default locale.
fun String.Companion.format(
format: String,
vararg args: Any?
): StringisSupplementaryCodePoint
Checks if the codepoint specified is a supplementary codepoint or not.
fun Char.Companion.isSupplementaryCodePoint(
codepoint: Int
): BooleanisSurrogatePair
fun Char.Companion.isSurrogatePair(
high: Char,
low: Char
): BooleantoCodePoint
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