10
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

swift3で文字列をsplitする

Last updated at Posted at 2016-12-01

Swift3で文字列をsplitする

String型の日付を"/"でsplitしたかったんだけど、なかなか見つけれなかったのでメモ

let str = "2016/01/31"
let split = str.components(separatedBy: "/")
print(split)
// => ["2016", "01", "31"]

2系でのcomponentsSeparatedByStringとかcharacterに変換してとかはあったけど、components使う形のが見当たらなかった。

ちゃんとマニュアル読もう。。
https://developer.apple.com/reference/swift/string


2017/9/14 追記

Xcode 9.0以上でsplitがbeta版でできたらしい。
https://developer.apple.com/documentation/swift/string/2894564-split


10
14
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
10
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?