LoginSignup
2
3

More than 5 years have passed since last update.

[Swift] String配列内の空文字列を全削除

Posted at

文字列配列から空文字の要素を取り除く方法。

Array#filter()使うと楽。

let testArray : [String] = [
    "",
    "abc",
    "",
    "def",
    ""
]

let resultArray = testArray.filter{!$0.isEmpty}
print(resultArray)  //["abc", "def"]

以上。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3