どうも、ちょげ(@chogetarou)です。
drop()を使って文字列の最初の文字を削除する方法を紹介します。
方法

drop()を使って文字列の先頭の文字を削除するには、引数を使います。
まず、文字列からdrop()を呼び出します。
そして、drop()の引数に「1」を指定します。
val result = text.drop(1)
上記のdrop()は、呼び出した文字列の先頭の文字を削除した文字列を返します。
使用例
fun main() {
val text = "123456789"
val text2 = "Hello,Kotlin"
val result = text.drop(1)
val result2 = text2.drop(1)
println(result)
println(result2)
}
出力:
23456789
ello,Kotlin
コメント