本文介绍了Objective-C 中的转义引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using this code snippet to encode characters to be friendly with a POST request:

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

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

Which works great, but does not add escape Quotation marks: "

如何在 IOS 中转义引号?

How do I escape Quotation marks in IOS?

推荐答案

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

I needed to take the user inputted NSString from [textField text] and make sure that if there are quotation marks in the string, they are escaped properly in order to send through a POST statement.

我的解决方案是:

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

这篇关于Objective-C 中的转义引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 09:35