gpt4 book ai didi

Swift 通过添加百分比创建字符串

转载 作者:行者123 更新时间:2023-11-30 11:19:41 25 4
gpt4 key购买 nike

我如何将其转换为当前的 swift 语法。我过得很艰难。

extension String {
var escaped: String {
return CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,self as CFString!,"[]." as CFString!,":/?&=;+!#$()@',*" as CFString!,CFStringConvertNSStringEncodingToEncoding(String.Encoding.utf8.rawValue)) as String
}
}

最佳答案

简单地说:

var escaped: String {
let allowedCharacters = CharacterSet(charactersIn: ":/?&=;+!#$()@',*")
return addingPercentEncoding(withAllowedCharacters: allowedCharacters)!
}

关于Swift 通过添加百分比创建字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51419627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com