LoginSignup
2
1

More than 5 years have passed since last update.

文字列を任意の文字列で分割する方法

Last updated at Posted at 2015-12-07

例えば、

2015.12.11 14:34:502015.12.1114:34:50 のように、間の半角空白で分割する。

環境

  • Xcode 7.1.1
  • Swift 2.1

方法

componentsSeparatedByString(separator: String) -> [String]を使用する。

- 分割に指定する文字列は削除される
- 分割後は配列が返される
- 最初または最後に分割指定文字列が含まれていた場合、該当インデックスの値は空""になる

let title = "2015.12.11 14:34:50"
let titleArray = title.componentsSeparatedByString(" ")
print(titleArray[0])  // 2015.12.11
print(titleArray[1])  // 14:34:50
2
1
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
1