swift Uint8数组如何转化为字符串

@objc class func switchHEXstring_to_string(chars:[UInt8]) -> String {

    var   chaArr : [UInt8] = [UInt8]()
    for  b : UInt8 in chars {
        if b == 255 {  //将255的数据清除
            
        }else {
            chaArr.append(b)
        }
    }
    
    var  str : String? = String(bytes: chaArr, encoding: String.Encoding.utf8)
    return  str ?? ""
}

//过滤数字是0的情况
@objc class func switchHEXstring_to_string_noneZero(chars:[UInt8]) -> String {

    var   chaArr : [UInt8] = [UInt8]()
    for  b : UInt8 in chars {
        if b == 0 {  //将0的数据清除
            
        }else {
            chaArr.append(b)
        }
    }
    
    var  str : String? = String(bytes: chaArr, encoding: String.Encoding.utf8)
    return  str ?? ""
}

你可能感兴趣的:(swift Uint8数组如何转化为字符串)