String

The String class represents character strings. All string literals in Kotlin programs, such as "abc", are implemented as instances of this class.

Since Kotlin

1.0

The String class represents character strings. All string literals in Kotlin programs, such as "abc", are implemented as instances of this class.

Since Kotlin

1.1

Constructors

Link copied to clipboard
fun String()
fun String()

Types

Link copied to clipboard
object Companion
Since Kotlin 1.0
object Companion
Since Kotlin 1.1

Functions

Link copied to clipboard
open operator override fun compareTo(other: String): Int

Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it's less than other, or a positive number if it's greater than other.

Since Kotlin 1.0
open operator override fun compareTo(other: String): Int

Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it's less than other, or a positive number if it's greater than other.

Since Kotlin 1.1
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Since Kotlin 1.0
open operator override fun equals(other: Any?): Boolean
Since Kotlin 1.1
Link copied to clipboard
open operator override fun get(index: Int): Char

Returns the character of this string at the specified index.

Since Kotlin 1.0
open operator override fun get(index: Int): Char

Returns the character of this string at the specified index.

Since Kotlin 1.1
Link copied to clipboard
operator fun plus(other: Any?): String

Returns a string obtained by concatenating this string with the string representation of the given other object.

Since Kotlin 1.0
operator fun plus(other: Any?): String

Returns a string obtained by concatenating this string with the string representation of the given other object.

Since Kotlin 1.1
Link copied to clipboard
open override fun subSequence(startIndex: Int, endIndex: Int): CharSequence

Returns a new character sequence that is a subsequence of this character sequence, starting at the specified startIndex and ending right before the specified endIndex.

Since Kotlin 1.0
open override fun subSequence(startIndex: Int, endIndex: Int): CharSequence

Returns a new character sequence that is a subsequence of this character sequence, starting at the specified startIndex and ending right before the specified endIndex.

Since Kotlin 1.1
Link copied to clipboard
open override fun toString(): String
Since Kotlin 1.0
open override fun toString(): String
Since Kotlin 1.1

Properties

Link copied to clipboard
open override val length: Int

Returns the length of this character sequence.

Since Kotlin 1.0
open override val length: Int

Returns the length of this character sequence.

Since Kotlin 1.1

Extensions

Link copied to clipboard
inline fun String.byteInputStream(charset: Charset = Charsets.UTF_8): ByteArrayInputStream
inline fun String.byteInputStream(charset: Charset = Charsets.UTF_8): ByteArrayInputStream

Creates a new byte input stream for the string.

Since Kotlin 1.0
Link copied to clipboard
inline fun String.codePointAt(index: Int): Int
inline fun String.codePointAt(index: Int): Int

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

Since Kotlin 1.0
Link copied to clipboard
inline fun String.codePointBefore(index: Int): Int
inline fun String.codePointBefore(index: Int): Int

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

Since Kotlin 1.0
Link copied to clipboard
inline fun String.codePointCount(beginIndex: Int, endIndex: Int): Int
inline fun String.codePointCount(beginIndex: Int, endIndex: Int): Int

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

Since Kotlin 1.0
Link copied to clipboard
inline fun String.concat(str: String): String
inline fun String.concat(str: String): String
Since Kotlin 1.1
Link copied to clipboard
inline fun String.contentEquals(charSequence: CharSequence): Boolean
inline fun String.contentEquals(charSequence: CharSequence): Boolean

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

Since Kotlin 1.0
inline fun String.contentEquals(stringBuilder: StringBuffer): Boolean
inline fun String.contentEquals(stringBuilder: StringBuffer): Boolean

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

Since Kotlin 1.0
Link copied to clipboard
inline fun String.format(vararg args: Any?): String
inline fun String.format(vararg args: Any?): String

Uses this string as a format string and returns a string obtained by substituting the specified arguments, using the default locale.

Since Kotlin 1.0
inline fun String.format(locale: Locale, vararg args: Any?): String
inline fun String.format(locale: Locale, vararg args: Any?): String

Uses this string as a format string and returns a string obtained by substituting the specified arguments, using the specified locale.

Since Kotlin 1.0
Link copied to clipboard
inline fun String.intern(): String
inline fun String.intern(): String

Returns a canonical representation for this string object.

Since Kotlin 1.0
Link copied to clipboard
inline fun String.match(regex: String): Array<String>?
inline fun String.match(regex: String): Array<String>?
Since Kotlin 1.1
Link copied to clipboard
Since Kotlin 1.1
Link copied to clipboard
Since Kotlin 1.0
Link copied to clipboard
inline fun <R : Comparable<R>> CharSequence.maxBy(selector: (Char) -> R): Char?
inline fun <R : Comparable<R>> CharSequence.maxBy(selector: (Char) -> R): Char?
Since Kotlin 1.0
Link copied to clipboard
fun CharSequence.maxWith(comparator: Comparator<in Char>): Char?
fun CharSequence.maxWith(comparator: Comparator<in Char>): Char?
Since Kotlin 1.0
Link copied to clipboard
Since Kotlin 1.0
Link copied to clipboard
inline fun <R : Comparable<R>> CharSequence.minBy(selector: (Char) -> R): Char?
inline fun <R : Comparable<R>> CharSequence.minBy(selector: (Char) -> R): Char?
Since Kotlin 1.0
Link copied to clipboard
fun CharSequence.minWith(comparator: Comparator<in Char>): Char?
fun CharSequence.minWith(comparator: Comparator<in Char>): Char?
Since Kotlin 1.0
Link copied to clipboard
inline fun String.offsetByCodePoints(index: Int, codePointOffset: Int): Int
inline fun String.offsetByCodePoints(index: Int, codePointOffset: Int): Int

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

Since Kotlin 1.0
Link copied to clipboard
operator fun String?.plus(other: Any?): String
operator fun String?.plus(other: Any?): String

Concatenates this string with the string representation of the given other object. If either the receiver or the other object are null, they are represented as the string "null".

Since Kotlin 1.0
operator fun String?.plus(other: Any?): String
operator fun String?.plus(other: Any?): String

Concatenates this string with the string representation of the given other object. If either the receiver or the other object are null, they are represented as the string "null".

Since Kotlin 1.1
Link copied to clipboard
inline fun String.reader(): StringReader
inline fun String.reader(): StringReader

Creates a new reader for the string.

Since Kotlin 1.0
Link copied to clipboard
fun String.regionMatches(thisOffset: Int, other: String, otherOffset: Int, length: Int, ignoreCase: Boolean = false): Boolean
fun String.regionMatches(thisOffset: Int, other: String, 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.

Since Kotlin 1.0
Link copied to clipboard
fun CharSequence.split(regex: Pattern, limit: Int = 0): List<String>
fun CharSequence.split(regex: Pattern, limit: Int = 0): List<String>

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

Since Kotlin 1.0
Link copied to clipboard
inline fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray
inline fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray

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

Since Kotlin 1.0
Link copied to clipboard
inline fun String.toCharArray(destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = length): CharArray
inline fun String.toCharArray(destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = length): CharArray

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

Since Kotlin 1.0
Link copied to clipboard
inline fun String.toLowerCase(locale: Locale): String
inline fun String.toLowerCase(locale: Locale): String

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

Since Kotlin 1.0
Link copied to clipboard
inline fun String.toPattern(flags: Int = 0): Pattern
inline fun String.toPattern(flags: Int = 0): Pattern

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.

Since Kotlin 1.0
Link copied to clipboard

Returns a new SortedSet of all characters.

Since Kotlin 1.0
Link copied to clipboard
inline fun String.toUpperCase(locale: Locale): String
inline fun String.toUpperCase(locale: Locale): String

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

Since Kotlin 1.0