1.判斷是否數(shù)字
? ? // - 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、提取字符串里的數(shù)字
從字符串中提取數(shù)字
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)
? ? }