gpt4 book ai didi

objective-c - Objective-C 中的转义引号

转载 作者:可可西里 更新时间:2023-11-01 03:05:27 25 4
gpt4 key购买 nike

我正在使用此代码片段对字符进行编码,以便对 POST 请求友好:

   NSString *unescaped = [textField text];
NSString *escapedString = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge_retained CFStringRef)unescaped,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);

效果很好,但不添加转义引号:"

如何在 IOS 中转义引号?

最佳答案

我需要从 [textField text] 获取用户输入的 NSString 并确保如果字符串中有引号,它们会被正确转义以便通过 POST 语句发送。

我的解决方案是:

unescaped = [unescaped stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];

关于objective-c - Objective-C 中的转义引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10117031/

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