如何从NSString中删除引号?

时间:2010-11-08 05:21:24

标签: iphone objective-c xcode

我正在尝试从以下内容中删除引号:

“你好”

这样字符串就是:

您好

2 个答案:

答案 0 :(得分:14)

查看Apple的文档:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/

你可能想要:

stringByReplacingOccurrencesOfString:withString:

返回一个新字符串,其中接收器中所有出现的目标字符串都被另一个给定的字符串替换。

- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement

所以,这样的事情应该有效:

newString = [myString stringByReplacingOccurrencesOfString:@"\"" withString:@""];

答案 1 :(得分:4)

我只想删除第一个引号和最后一个引号,而不是字符串中的引号,所以这就是我所做的:

challengeKey = @"\"I want to \"remove\" the quotes.\"";
challengeKey = [challengeKey substringFromIndex:1];
challengeKey = [challengeKey substringToIndex:[challengeKey length] - 1];

希望这可以帮助其他人寻找同样的事情。 NSLog,你会得到这个输出:

I want to "remove" the quotes.
相关问题