Swift

[ Swift ] isCase | isLowercase | isUppercase

Forest Yun 2023. 10. 4. 13:42
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"
 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

 

 

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