String에 있는 소문자들을 모두 대문자로 변환한다.
fun String.uppercase(): String
String에 있는 대문자들을 소문자로 변환한다.
fun String.lowercase(): String
예시)
val lowerToUpper = "ABCdef"
println(lowerToUpper.uppercase()) // ABCDEF
val upperToLower = "ABCdef"
println(upperToLower.lowercase()) // abcdef
대문자인 문자 하나를 소문자로 변환한다.
fun Char.uppercaseChar(): Char
소문자인 문자 하나를 대문자로 변환한다.
fun Char.lowercaseChar(): Char
예시)
val list = listOf('A','B','C','d','e','f')
val lowerToUpper = list.map { it.uppercaseChar() }
val upperToLower = list.map { it.lowerToUpper() }
println(lowerToUpper) // [A, B, C, D, E, F]
println(upperToLower) // [a, b, c, d, e, f]
prefix
를 떼어낸 String을 반환
String의 시작이 prefix
와 일치하지 않으면 원본 String을 반환
원본 String을 파괴하지 않는다.
fun String.removePrefix(prefix: CharSequence): String
removePrefix와 마찬가지
fun String.removeSuffix(suffix: CharSequence): String
delimiter
를 prefix와 suffix로 동시에 가지면 prefix와 suffix를 제거한 String을 반환
prefix와 suffix 둘 중 하나라도 delimiter
와 같지 않으면 아무일도 일어나지 않음
원본 String을 파괴하지 않는다.
fun String.removeSurrounding(delimiter: CharSequence): String fun String.removeSurrounding( prefix: CharSequence, suffix: CharSequence ): String
예시)
val string = ".abc."
println(string.removePrefix(".")) // abc.
println(string.removePrefix("^")) // .abc.
println(string.removeSuffix(".")) // .abc
println(string.removeSuffix("^")) // .abc.
println(string.removeSurrounding(".")) // abc
println(string.removeSurrounding("^")) // .abc.
println(string.removeSurrounding(".", ".")) // abc
println(string.removeSurrounding(".", "^")) // .abc.