Search Your Question

Write a program for get only numeric from "a,b,1,2,c,4,d,3"

Ans :  

let string = "I have to buy 3 apples, 7 bananas, 10eggs"
let stringArray = string.components(separatedBy: CharacterSet.decimalDigits.inverted)
for item in stringArray {
    if let number = Int(item) {
        print("number: \(number)")
    }

}

Output : 

3
7
10


No comments:

Post a Comment

Thanks