删除 NSString 的一部分并将其复制到另一个 NSString
所以我有一个 NSString,让我们这么说: NSString *mainString = @"My Name is Andrew (I likecomputer)";
我想从 mainString 中删除从“(”到“)”的所有内容。我想将“()”之间的所有内容放入子字符串中。
例如:
NSString *mainString = @"My Name is Andrew (I like computers)";
NSString *subString;
//The code I need help with
mainString = @"y Name is Andrew ";
subString = @"I like computers";
我希望这是有道理的。这真的会对我有帮助。提前致谢。我一直在使用 NSRange
和 NSMutableStrings
但遇到了麻烦。提前致谢。
So I have an NSString, lets say it: NSString *mainString = @"My Name is Andrew (I like computers)";
And I want remove everything from the "(" to the ")" from mainString. And I want to put everything in between the "()" into a subString.
For example:
NSString *mainString = @"My Name is Andrew (I like computers)";
NSString *subString;
//The code I need help with
mainString = @"y Name is Andrew ";
subString = @"I like computers";
I hope this makes sense. It would really help me. Thanks in Advance. I've been playing with NSRange
and NSMutableStrings
but I'm having trouble. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 darvids0n 在下面的评论中提到的:
and as darvids0n has mentioned in below comment:
这可能是一个更简单的方法:
This is probably an easier way: