在Objective-C中转义行情 [英] Escape Quotes in Objective-C
本文介绍了在Objective-C中转义行情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
NSString * unescaped = [ textField文本];
NSString * escapedString =(__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge_retained CFStringRef)unescaped,
NULL,
(CFStringRef)@!* );; @& = + $,/?%#[],
kCFStringEncodingUTF8);
哪个效果好,但不添加转义引号:
如何在IOS中转义引号?
解决方案
我需要把用户输入的NSString从 [textField text]
,并确保如果字符串中有引号,则它们会正确转义,以便通过POST语句发送。
我的解决方案是:
unescaped = [unescaped stringByReplacingOccurrencesOfString:@\withString:@\\\] ;
谢谢
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: "
How do I escape Quotation marks in IOS?
解决方案
I think I didn't word the question correctly.
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.
My solution was:
unescaped = [unescaped stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
Thanks
这篇关于在Objective-C中转义行情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文