[swift] 공백 사용
- 문자열 리터럴에 공백 추가하기:
let message = "안녕하세요, Swift입니다."
- 문자열 연결로 공백 추가하기:
let firstName = "John" let lastName = "Doe" let fullName = firstName + " " + lastName
- 공백으로 문자열 분할하기:
let fullName = "John Doe" let components = fullName.components(separatedBy: " ") let firstName = components.first // "John" let lastName = components.last // "Doe"
- 공백 제거하기:
let stringWithWhitespace = " Hello, World! " let trimmedString = stringWithWhitespace.trimmingCharacters(in: .whitespaces)
- 여러 줄을 가진 문자열에 공백 추가하기:
let multilineString = """ 안녕하세요, Swift입니다. """
공백은 Swift에서 문자열을 다룰 때 유용하게 사용되는 기능 중 하나입니다. 이를 통해 문자열을 조작하고 가독성을 높일 수 있습니다.