![](/img/trans.png)
[英]How can I remove specific characters from an NSString programmatically?
[英]How can I remove quotes from an NSString?
我试图从以下内容中删除引号:
“你好”
所以字符串只是:
你好
查看Apple的文档:
你可能想要:
stringByReplacingOccurrencesOfString:withString:
返回一个新字符串,其中接收器中所有出现的目标字符串都被另一个给定字符串替换。
- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement
所以,这样的事情应该有效:
newString = [myString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
我只想删除第一个引号和最后一个引号,而不是字符串中的引号,所以这就是我所做的:
challengeKey = @"\"I want to \"remove\" the quotes.\"";
challengeKey = [challengeKey substringFromIndex:1];
challengeKey = [challengeKey substringToIndex:[challengeKey length] - 1];
希望这有助于其他人寻找同样的事情。 NSLog,你会得到这个输出:
I want to "remove" the quotes.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.