- 멀티라인 문자열(Multiline Strings): 여러 줄로 된 문자열 출력
- trimIndent: 모든 줄에서 공통의 들여쓰기 제거
- trimMargin: 특정 마진 기호를 기준으로 여백을제거
일반 문자열
val regularString = "My text"
멀티라인 문자열
- 줄바꿈을 포함한 여러 줄의 텍스트를 그대로 유지
val multiRowString = """
First line of the string
Second line of the string
"""
//출력
// *First line of the string\n
// *Second line of the string
trimIndent:
- 문자열의 모든 줄에서 가장 작은 공통 들여쓰기를 제거
- 문자열의 첫 번째 및 마지막 줄이 비어 있으면 이 줄들도 제거
val multiRowString = """
*First line of the string
*Second line of the string
"""
println(multiRowString.trimIndent())
//출력
//*First line of the string
//*Second line of the string
trimMargin:
- 문자열의 모든 줄에서 특정 마진 기호(예: |, *)를 기준으로 여백 제거
- 기본적으로 | 기호를 사용하지만, 다른 기호를 지정 가능
val multiRowString = """
*First line of the string
*Second line of the string
"""
println(multiRowString.trimMargin("*"))
//출력
//First line of the string
//Second line of the string
'코틀린' 카테고리의 다른 글
[코틀린 Kotlin] lines - 줄 단위로 split 하여 리스트로 반환 (0) | 2024.09.07 |
---|---|
[코틀린 Kotlin] 조건식, 변수 값 비교에 따른 when 표현식 (0) | 2024.09.07 |
[코틀린 Kotlin] uppercase - 대문자로 변경 (+지정 국가 언어로 변환) (1) | 2024.09.06 |
[코틀린 Kotlin] isLetter - 문자가 알파벳인지 여부 확인 (0) | 2024.09.06 |
[코틀린 Kotlin] removeSuffix - 문자열에서 특정 접미사를 제거한 새로운 문자열 반환 함수 (0) | 2024.09.06 |