Objective-C/iPhone - 字符串替换
我将如何删除以下 NSString
中的“&expires_in=87131”:
显然,值 87131 将来可能会发生变化,并且它始终是字符串的最后一部分。
NSString *accessToken = @"136369349714439%7C2.nNIKZW8Z7Yw_aaaffqKv7lVFYJg__.86400.1301824800-705896566%7Cp-z9A68pJqTDNjEMj0TrHogc2bw&expires_in=87131";
NSString *newStr = [accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
How would I go about removing the "&expires_in=87131" within the following NSString
:
Obviously the value 87131 may change in the future and it's always the last part of the string as well.
NSString *accessToken = @"136369349714439%7C2.nNIKZW8Z7Yw_aaaffqKv7lVFYJg__.86400.1301824800-705896566%7Cp-z9A68pJqTDNjEMj0TrHogc2bw&expires_in=87131";
NSString *newStr = [accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果保证字符串中只有一个 & 符号:
If the string is guaranteed to only have one ampersand in it:
有关“修复 %7C 字符”,请参阅 NSString stringByReplacingPercentEscapesUsingEncoding
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html# //apple_ref/occ/instm/NSString/stringByReplacingPercentEscapesUsingEncoding
For 'fixing the %7C characters' see NSString stringByReplacingPercentEscapesUsingEncoding
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/stringByReplacingPercentEscapesUsingEncoding