[Swift]文字列が空かどうかを判断する方法

書式
文字列.isEmpty
文字列.count

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let cft = ""
//isEmpty
if cft.isEmpty {
print("文字列が空です")
}
//長さcount
if cft.count == 0 {
print("文字列が空です")
}
//""文字列
if cft == "" {
print("文字列が空です")
}
let cft = "" //isEmpty if cft.isEmpty { print("文字列が空です") } //長さcount if cft.count == 0 { print("文字列が空です") } //""文字列 if cft == "" { print("文字列が空です") }
let cft = ""
//isEmpty
if cft.isEmpty {
    print("文字列が空です")
}
//長さcount
if cft.count == 0 {
    print("文字列が空です")
}
//""文字列
if cft == "" {
    print("文字列が空です")
}

結果
$ swift stremp.swift
文字列が空です
文字列が空です
文字列が空です

Swift

Posted by arkgame