DEV Community

Cover image for Split Array separated by...

Split Array separated by...

Hi,
my way to split one array (of String) in two or more var

sometimes you have a Date() in a String format, and you want only the year.

you can use .components(separatedBy: "/")

func splitArray() {

    let myARRAY = "20/09/2021"
    let SplittedArray = myARRAY.components(separatedBy: "/")

    let DAY = SplittedArray[0]
    let MONTH = SplittedArray[1]
    let YEAR = SplittedArray[2]

        print("\(DAY), \(MONTH), \(YEAR)")
    }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)