LoginSignup
0
2

More than 1 year has passed since last update.

【Swift】文字列を分割して配列にする

Posted at

はじめに

PythonのsplitみたいなことをSwiftでしたいと思った時にやり方がわからなかったので記録しておきます。

やりかた

Pyhton

str = "1 2 3 4 5"

print(str.split(" "))

# ["1", "2", "3", "4", "5"]

Swift

import Foundation

let str = "1 2 3 4 5"

print(str.components(separatedBy: " "))

// ["1", "2", "3", "4", "5"]

おわり

似てるからごっちゃになる!

0
2
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
0
2