【发布时间】:2011-11-03 08:30:35
【问题描述】:
如何从NSString 中删除某些文本,例如“http://”?它必须完全按照这个顺序。感谢您的帮助!
这是我正在使用的代码,但是 http:// 没有被删除。相反,它显示为http://http://www.example.com。我该怎么办?谢谢!
NSString *urlAddress = addressBar.text;
[urlAddress stringByReplacingOccurrencesOfString:@"http://" withString:@""];
urlAddress = [NSString stringWithFormat:@"http://%@", addressBar.text];
NSLog(@"The user requested this host name: %@", urlAddress);
【问题讨论】:
-
您再次添加相同的字符串。如果要删除 http://,则不需要第 3 行
-
如果用户没有输入 http://,那么 UIWebView 将起作用。但是,如果用户确实输入了 http://,那么 UIWebView 将无法工作。通过删除任何 http:// 然后重新插入一次,我可以保证 NSString 看起来像这样:http://www.google.com
标签: iphone objective-c ios ipad nsstring