titlecase

Common
JVM
JS
Native
1.5
fun Char.titlecase(): String
(source)

Converts this character to title case using Unicode mapping rules of the invariant locale.

This function supports one-to-many character mapping, thus the length of the returned string can be greater than one. For example, '\uFB00'.titlecase() returns "\u0046\u0066", where '\uFB00' is the LATIN SMALL LIGATURE FF character (). If this character has no title case mapping, the result of uppercase is returned instead.

import java.util.*
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val chars = listOf('a', 'Dž', 'ʼn', '+', 'ß')
val titlecaseChar = chars.map { it.titlecaseChar() }
val titlecase = chars.map { it.titlecase() }
println(titlecaseChar) // [A, Dž, ʼn, +, ß]
println(titlecase) // [A, Dž, ʼN, +, Ss]
//sampleEnd
}
JVM
1.5
fun Char.titlecase(locale: Locale): String
(source)

Converts this character to title case using Unicode mapping rules of the specified locale.

This function supports one-to-many character mapping, thus the length of the returned string can be greater than one. For example, '\uFB00'.titlecase(Locale.US) returns "\u0046\u0066", where '\uFB00' is the LATIN SMALL LIGATURE FF character (). If this character has no title case mapping, the result of uppercase(locale) is returned instead.

import java.util.*
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val chars = listOf('a', 'Dž', 'ʼn', '+', 'ß', 'i')
val titlecase = chars.map { it.titlecase() }
val turkishLocale = Locale.forLanguageTag("tr")
val titlecaseTurkish = chars.map { it.titlecase(turkishLocale) }
println(titlecase) // [A, Dž, ʼN, +, Ss, I]
println(titlecaseTurkish) // [A, Dž, ʼN, +, Ss, İ]
//sampleEnd
}