swift - Checking the String whether it is the Number(Double) of -
question. necessary make check string whether number(double)? exemple:
var s1:string = "df1231" var s2:string = "1231,3123" if s1.isdouble { println("true.this number!") } else { println("false.this not number!") //will give } if s2.isdouble { println("true.this number!") //will give } else { println("false.this not number!") }
not sure needs exactly, straightforward way be:
func isdouble(text:string) -> bool { guard let _ = double(text.stringbyreplacingoccurrencesofstring(",", withstring: ".")) else { return false } return true } isdouble("df1231") // returns false isdouble("1231,3123") // returns true
you can copy paste playground see work.
Comments
Post a Comment