文字列配列から空文字の要素を取り除く方法。
Array#filter()
使うと楽。
let testArray : [String] = [
"",
"abc",
"",
"def",
""
]
let resultArray = testArray.filter{!$0.isEmpty}
print(resultArray) //["abc", "def"]
以上。
More than 5 years have passed since last update.
文字列配列から空文字の要素を取り除く方法。
Array#filter()
使うと楽。
let testArray : [String] = [
"",
"abc",
"",
"def",
""
]
let resultArray = testArray.filter{!$0.isEmpty}
print(resultArray) //["abc", "def"]
以上。
Register as a new user and use Qiita more conveniently