Swift

Swift 字符串中查找指定字符 并 分割

    public class func splitFindItem(findStr:String, totalStr:String) -> [String] {
        
        let scanner = Scanner(string: totalStr)
        
        var keyWordSplit: [String] = []
        
        while !scanner.isAtEnd {
            if let op = scanner.scanUpToString(findStr) {
                if op != totalStr {
                    keyWordSplit.append(op)
                }
            }
            
            if let op = scanner.scanString(findStr) {
                keyWordSplit.append(op as String)
            }
        }
        return keyWordSplit
    }

splitFindItem(findStr:”23″, totalStr:”12345″)

[“1”, “23”, “45”]