删除部分NSString [英] Remove part of an NSString
本文介绍了删除部分NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个NSString如下:
I have an NSString as follows:
<img alt="996453912" src="http://d2gg0uigdtw9zz.cloudfront.net/large/996453912.jpg" /><a href="http://www.dealcatcher.com/shop4tech-coupons">Shop4Tech Coupons</a>
我只需要第一部分(在之前< a href
part),我无法弄清楚如何删除第二部分。
I only need the first part (before the <a href
part), and I cannot figure out how to remove the second part.
我尝试了一下,但它没有用。
I have tried a ton, but it has not worked.
推荐答案
使用类似于:
NSRange rangeOfSubstring = [string rangeOfString:@"<a href"];
if(rangeOfSubstring.location == NSNotFound)
{
// error condition — the text '<a href' wasn't in 'string'
}
// return only that portion of 'string' up to where '<a href' was found
return [string substringToIndex:rangeOfSubstring.location];
所以两个相关的方法是 substringToIndex:和 rangeOfString:。
So the two relevant methods are substringToIndex: and rangeOfString:.
这篇关于删除部分NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文