W3cubDocs

/Kotlin

toCharArray

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun String.toCharArray(): CharArray

Returns a CharArray containing characters of this string.

Platform and version requirements: JVM (1.4), JS (1.4)
fun String.toCharArray(
    startIndex: Int = 0, 
    endIndex: Int = this.length
): CharArray
Platform and version requirements: Native (1.3)
fun String.toCharArray(
    startIndex: Int, 
    endIndex: Int
): CharArray

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

Parameters

startIndex - the beginning (inclusive) of the substring, 0 by default.

endIndex - the end (exclusive) of the substring, length of this string by default.

Exceptions

IndexOutOfBoundsException - if startIndex is less than zero or endIndex is greater than the length of this string.

IllegalArgumentException - if startIndex is greater than endIndex.

Platform and version requirements: JS (1.4), Native (1.4)
fun StringBuilder.toCharArray(
    destination: CharArray, 
    destinationOffset: Int = 0, 
    startIndex: Int = 0, 
    endIndex: Int = this.length)

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

Parameters

destination - the array to copy to.

destinationOffset - the position in the array to copy to, 0 by default.

startIndex - the beginning (inclusive) of the range to copy, 0 by default.

endIndex - the end (exclusive) of the range to copy, length of this string builder by default.

Exceptions

IndexOutOfBoundsException - or IllegalArgumentException when startIndex or endIndex is out of range of this string builder indices or when startIndex > endIndex.

IndexOutOfBoundsException - when the subrange doesn't fit into the destination array starting at the specified destinationOffset, or when that index is out of the destination array indices range.

Platform and version requirements: JVM (1.0)
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.

Parameters

destination - the array to copy to.

destinationOffset - the position in the array to copy to.

startIndex - the start offset (inclusive) of the substring to copy.

endIndex - the end offset (exclusive) of the substring to copy.

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