解決方案來源:
Filter non-digits from string
sStrTmp2 = sStrTmp1.components(separatedBy:CharacterSet.decimalDigits.inverted).joined(separator: "") if( sStrTmp2.count > 0) { if let nNumber = Int(sStrTmp2) { } }
字串的字元檢查
sStrTmp1 = "0123456789" for nChar in sStrTmp1 /* 檢查是否為數字字元 */ { if( nChar < "0" || nChar > "9") { bIsNumber = false } }
沒有留言:
張貼留言