지정된 startIndex 부터 시작하여 지정된 문자가 마지막으로 나타나는 이 문자 시퀀스 내의 인덱스를 반환합니다.
반환 char 의 마지막 발생 인덱스를 반환하거나, 아무것도 발견되지 않으면 -1 을 반환합니다.
public fun CharSequence.lastIndexOf(string: String, startIndex: Int = lastIndex, ignoreCase: Boolean = false): Int {
return if (ignoreCase || this !is String)
indexOf(string, startIndex, 0, ignoreCase, last = true)
else
nativeLastIndexOf(string, startIndex)
}
val string = "HelloWorld"
print(string.lastIndexOf("abc")) // -1
print(string.lastIndexOf("Hello")) // 0
print(string.lastIndexOf("World")) // 5
'코틀린 > [Elements] 요소 작업' 카테고리의 다른 글
[Kotlin][String] startsWith / endsWith (0) | 2024.08.29 |
---|---|
[Kotlin][Collection] last / lastOrNull (0) | 2024.08.20 |
[Kotlin][Collection] indexOf / indexOfFirst / indexOfLast (0) | 2024.08.20 |