kotlin lowercase()で文字列の先頭だけ小文字に変更する

環境
Windows10 Home 64bit
Java 19.0.1
Kotlin 1.7.20-release-201

書式
文字列.replaceFirstChar { it.lowercase() }
lowercase()を使って文字列の先頭だけ小文字に変更します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fun main() {
println( "Stu".replaceFirstChar { it.lowercase() } )
println( "ATu".replaceFirstChar { it.lowercase() } )
println( "Abc".replaceFirstChar { it.lowercase() } )
}
fun main() { println( "Stu".replaceFirstChar { it.lowercase() } ) println( "ATu".replaceFirstChar { it.lowercase() } ) println( "Abc".replaceFirstChar { it.lowercase() } ) }
fun main() {
   

    println( "Stu".replaceFirstChar { it.lowercase() } ) 

    println( "ATu".replaceFirstChar { it.lowercase() } ) 

    println( "Abc".replaceFirstChar { it.lowercase() } ) 
}

実行結果
stu
aTu
abc

Kotlin

Posted by arkgame