标签:
// 递归调用获取字符串内所有的src地址
-(NSMutableArray *)getImageSrcUrlWithString:(NSString *)str withArray:(NSMutableArray *)myArray
{
NSMutableString *sourceStr = [NSMutableString stringWithString:str];
NSString *srcStartPatten= @"src=\"";
NSString *srcEndPatten = @"\"";
NSRange startRange = [sourceStr rangeOfString:srcStartPatten];
if(startRange.location == NSNotFound)
{
return myArray;
}
int startIndex = (int)startRange.location;
if(startIndex >= 0)
{
sourceStr = [sourceStr substringFromIndex:startIndex+5];
NSRange endRange = [sourceStr rangeOfString:srcEndPatten];
int endIndex = (int)endRange.location;
if(endIndex >= 0)
{
NSString *src = [sourceStr substringToIndex:endIndex];
[myArray addObject:src];
NSString *leftStr = [sourceStr substringFromIndex:endIndex+3];
[self getImageSrcUrlWithString:leftStr withArray:myArray];
}
}
return myArray;
}
标签:
原文地址:http://www.cnblogs.com/xiangjune/p/4922577.html