繁体   English   中英

如何从NSString中删除引号?

[英]How can I remove quotes from an NSString?

我试图从以下内容中删除引号:

“你好”

所以字符串只是:

你好

查看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:@""];

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM