swift 之 URL编码

前端之家收集整理的这篇文章主要介绍了swift 之 URL编码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
func encodeEscapesURL(value:String) -> String {
        let str:NSString = value
        let originalString = str as CFStringRef
        let charactersToBeEscaped = "!*'();:@&=+$,/?%#[]" as CFStringRef  //":/?&=;+!@#$()',*" //转意符号
        //let charactersToLeaveUnescaped = "[]." as CFStringRef //保留的符号
        let result =
        CFURLCreateStringByAddingPercentEscapes(kcfAllocatorDefault,originalString,nil,//charactersToLeaveUnescaped,
            charactersToBeEscaped,CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) as NSString

        return result as String
    }

猜你在找的Swift相关文章