length

expect abstract val length: Int(source)

Returns the length of this character sequence.

The length is measured in the number of Chars constituting the sequence. It implies that the length may not correspond to the number of printed graphemes: some Chars could represent control, non-printable, or diaeresis symbols, others could form UTF-16 surrogate pairs, required to encode Unicode code points not representable by a single Char.

Since Kotlin

1.0

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   assertEquals(0, "".length)
assertEquals(6, "Kotlin".length)
// 🥦 is represented by a pair of UTF-16 characters, thus the string's length is 2, not 1
assertEquals(2, "🥦".length) 
   //sampleEnd
}
actual abstract val length: Int(source)

Returns the length of this character sequence.

The length is measured in the number of Chars constituting the sequence. It implies that the length may not correspond to the number of printed graphemes: some Chars could represent control, non-printable, or diaeresis symbols, others could form UTF-16 surrogate pairs, required to encode Unicode code points not representable by a single Char.

Since Kotlin

1.1

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   assertEquals(0, "".length)
assertEquals(6, "Kotlin".length)
// 🥦 is represented by a pair of UTF-16 characters, thus the string's length is 2, not 1
assertEquals(2, "🥦".length) 
   //sampleEnd
}
actual abstract val length: Int(source)

Returns the length of this character sequence.

The length is measured in the number of Chars constituting the sequence. It implies that the length may not correspond to the number of printed graphemes: some Chars could represent control, non-printable, or diaeresis symbols, others could form UTF-16 surrogate pairs, required to encode Unicode code points not representable by a single Char.

Since Kotlin

1.0

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   assertEquals(0, "".length)
assertEquals(6, "Kotlin".length)
// 🥦 is represented by a pair of UTF-16 characters, thus the string's length is 2, not 1
assertEquals(2, "🥦".length) 
   //sampleEnd
}
actual abstract val length: Int(source)

Returns the length of this character sequence.

The length is measured in the number of Chars constituting the sequence. It implies that the length may not correspond to the number of printed graphemes: some Chars could represent control, non-printable, or diaeresis symbols, others could form UTF-16 surrogate pairs, required to encode Unicode code points not representable by a single Char.

Since Kotlin

1.3

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   assertEquals(0, "".length)
assertEquals(6, "Kotlin".length)
// 🥦 is represented by a pair of UTF-16 characters, thus the string's length is 2, not 1
assertEquals(2, "🥦".length) 
   //sampleEnd
}