capitalize
Deprecated
Warning since 1.5
Use replaceFirstChar instead.
Replace with
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
Returns a copy of this string having its first letter titlecased using the rules of the default locale, or the original string if it's empty or already starts with a title case letter.
The title case of a character is usually the same as its upper case with several exceptions. The particular list of characters with the special title case form depends on the underlying platform.
Since Kotlin
1.0Samples
import java.util.Locale
import kotlin.test.*
fun main() {
//sampleStart
println("abcd".capitalize()) // Abcd
println("Abcd".capitalize()) // Abcd
//sampleEnd
}
Deprecated
Warning since 1.5
Use replaceFirstChar instead.
Replace with
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
Returns a copy of this string having its first letter titlecased using the rules of the default locale, or the original string if it's empty or already starts with a title case letter.
The title case of a character is usually the same as its upper case with several exceptions. The particular list of characters with the special title case form depends on the underlying platform.
Since Kotlin
1.1Samples
import java.util.Locale
import kotlin.test.*
fun main() {
//sampleStart
println("abcd".capitalize()) // Abcd
println("Abcd".capitalize()) // Abcd
//sampleEnd
}
Deprecated
Warning since 1.5
Use replaceFirstChar instead.
Replace with
replaceFirstChar { if (it.isLowerCase()) it.titlecase(locale) else it.toString() }
Returns a copy of this string having its first letter titlecased using the rules of the specified locale, or the original string if it's empty or already starts with a title case letter.
The title case of a character is usually the same as its upper case with several exceptions. The particular list of characters with the special title case form depends on the underlying platform.
Since Kotlin
1.4Deprecated
Warning since 1.5
Use replaceFirstChar instead.
Replace with
import java.util.Locale
replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
Returns a copy of this string having its first letter titlecased using the rules of the default locale, or the original string if it's empty or already starts with a title case letter.
The title case of a character is usually the same as its upper case with several exceptions. The particular list of characters with the special title case form depends on the underlying platform.
Since Kotlin
1.0Samples
import java.util.Locale
import kotlin.test.*
fun main() {
//sampleStart
println("abcd".capitalize()) // Abcd
println("Abcd".capitalize()) // Abcd
//sampleEnd
}
Deprecated
Warning since 1.5
Use replaceFirstChar instead.
Replace with
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
Returns a copy of this string having its first letter titlecased using the rules of the default locale, or the original string if it's empty or already starts with a title case letter.
The title case of a character is usually the same as its upper case with several exceptions. The particular list of characters with the special title case form depends on the underlying platform.
Since Kotlin
1.3Samples
import java.util.Locale
import kotlin.test.*
fun main() {
//sampleStart
println("abcd".capitalize()) // Abcd
println("Abcd".capitalize()) // Abcd
//sampleEnd
}
Deprecated
Warning since 1.5
Use replaceFirstChar instead.
Replace with
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
Returns a copy of this string having its first letter titlecased using the rules of the default locale, or the original string if it's empty or already starts with a title case letter.
The title case of a character is usually the same as its upper case with several exceptions. The particular list of characters with the special title case form depends on the underlying platform.
Since Kotlin
1.8Samples
import java.util.Locale
import kotlin.test.*
fun main() {
//sampleStart
println("abcd".capitalize()) // Abcd
println("Abcd".capitalize()) // Abcd
//sampleEnd
}
Deprecated
Warning since 1.5
Use replaceFirstChar instead.
Replace with
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
Returns a copy of this string having its first letter titlecased using the rules of the default locale, or the original string if it's empty or already starts with a title case letter.
The title case of a character is usually the same as its upper case with several exceptions. The particular list of characters with the special title case form depends on the underlying platform.
Since Kotlin
1.8Samples
import java.util.Locale
import kotlin.test.*
fun main() {
//sampleStart
println("abcd".capitalize()) // Abcd
println("Abcd".capitalize()) // Abcd
//sampleEnd
}