1.判断是否数字
// - Parameter string: <#string description#>
/// - Returns: <#return value description#>
class func isPurnInt(string: String) -> Bool {
let scan: Scanner = Scanner(string:string)
varval:Int =0returnscan.scanInt(&val) && scan.isAtEnd
}
2、提取字符串里的数字
从字符串中提取数字
class func getIntFromString(str:String) -> String {
let scanner = Scanner(string: str)
scanner.scanUpToCharacters(from: CharacterSet.decimalDigits, into: nil)
varnumber :Int =0
scanner.scanInt(&number)
print(number)
return String(number)
}