String length: Difference between revisions

Content added Content deleted
(Add Plain English)
m (→‎{{header|Kotlin}}: made the kotlin example not use java)
Line 1,851: Line 1,851:


As each UTF-16 character occupies 2 bytes, it follows that the number of bytes occupied by the string will be twice the length:
As each UTF-16 character occupies 2 bytes, it follows that the number of bytes occupied by the string will be twice the length:
<syntaxhighlight lang="scala">// version 1.0.6
<syntaxhighlight lang="kotlin">
fun main(args: Array<String>) {
fun main() {
val s = "José"
val s = "José"
println("The char length is ${s.length}")
println("The char length is ${s.length}")
println("The byte length is ${Character.BYTES * s.length}")
println("The byte length is ${Char.SIZE_BYTES * s.length}")
}</syntaxhighlight>
}</syntaxhighlight>