开发者

NSString - how to check if it contains quotation marks <">

开发者 https://www.devze.com 2022-12-30 11:49 出处:网络
[[somestring substringtoindex:0] is equaltostring:@\"\"\"]; \'makes red\' the rest of the code. actually i can\'t开发者_运维问答 put quotation marks inside quotation marks. still, this is the characte

[[somestring substringtoindex:0] is equaltostring:@"""]; 'makes red' the rest of the code. actually i can't开发者_运维问答 put quotation marks inside quotation marks. still, this is the character i want to reffer. how should I do it in the correct way? thanks


To escape a character, use the backslash.

@"\"";

And to check if a string exists, use -rangeOfString:.

if ([string rangeOfString:@"\""].location != NSNotFound) { ... }

or -hasPrefix: and -hasSuffix:

if ([string hasPrefix:@"\""]) { ... }
0

精彩评论

暂无评论...
验证码 换一张
取 消