Finding out whether a string is numeric or not

前端 未结 18 1648
一个人的身影
一个人的身影 2020-12-07 15:24

How can we check if a string is made up of numbers only. I am taking out a substring from a string and want to check if it is a numeric substring or not.

NSS         


        
18条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 15:51

    Swift 3 solution if need to verify that the string has only digits:

    CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: myString))
    

提交回复
热议问题