728x90
isCase
ํด๋น Character์ ๋์๋ฌธ์ ๋ณํ์ด ๊ฐ๋ฅ ์ฌ๋ถ๋ฅผ ์ ์ ์๋ ํ๋กํผํฐ์ด๋ค. String์ด ์๋๋ผ Character์ ์ธ์คํด์ค ํ๋กํผํฐ๋ผ๋ ์ ์ ์ฃผ์ํ์. ๋์๋ฌธ์๊ฐ ์๋ ์์ด๋ ture์ด์ง๋ง ํ๊ธ, ์์ด์ฝ, ํน์๋ฌธ์ ๋ฑ์ false์ด๋ค.
let english = "a"
let korean = "๊ฐ"
let icon = "๐ง๐ปโ๏ธ"
let half = "½"
if english.first!.isCased {
print(english)
}
// Prints "a"
if korean.first!.isCased {
print(korean)
}
if icon.first!.isCased {
print(icon)
}
if half.first!.isCased {
print(half)
}
isLowercase | isUppercase
ํด๋น Character๊ฐ ์๋ฌธ์ ๋๋ ๋๋ฌธ์์ธ์ง ํ์ธํ๋ ํ๋กํผํฐ์ด๋ค.
let str = "A"
if str.isLowercase {
print("\(str)์ ์๋ฌธ์")
}
if str.iUppercase {
print("\(str)์ ๋๋ฌธ์")
}
์ฝ๋ฉํ ์คํธ
๋์๋ฌธ์๊ฐ ์์ฌ์๋ String์ ๋ฐ๋๋ก ๋ณํํด ์ถ๋ ฅํด์ผํ ๋, String์ ๊ฐ Character์ isLowercase๋ก ๊ฒ์ฌํ์ฌ ๊ตฌ๋ถํ ์ ์๋ค.
let str = "aBcDeFg"
print(str.map{ $0.isLowercase ? $0.uppercased : $0.lowercased }.joined() )
// Prints "AbCdEfG"
isCased
isLowercase
isUppercase
728x90
'Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ Swift ] Swift๋? (0) | 2023.10.08 |
---|---|
[ Swift ] zip(_:_:) (1) | 2023.10.08 |
[ Swift ] print(_:separator:terminator:) (0) | 2023.10.04 |
[ Swift ] ํ๋กํ ์ฝ ์งํฅ ํ๋ก๊ทธ๋๋ฐ (0) | 2023.09.24 |
[ Swift ] Serialization์ด๋? (0) | 2023.01.18 |