NSString * motherstr = @"w is w is w";
NSString * sonstr = @"w";
NSRange range = [motherstr rangeOfString:sonstr];
while(range.location != NSNotFound)
{
NSLog(@"start = %@",NSStringFromRange(range));
NSRange temp = NSMakeRange((range.location + range.length), (motherstr.length-(range.location+range.length)));
range =[motherstr rangeOfString:sonstr options:NSBackwardsSearch range:temp];
}
查找的時候只找到了開頭和結尾中的w,中間的包含的子串字符並沒有找到,想了很久也沒想出來為什麼,求大神告知。
NSString * motherstr = @"a is a , so a not equal b";
NSString * sonstr = @"a";
NSRange range = [motherstr rangeOfString:sonstr options:NSBackwardsSearch range:NSMakeRange(0, motherstr.length)];
//循環檢索
while(range.location != NSNotFound)
{
NSLog(@"start = %@",NSStringFromRange(range));
NSUInteger start = 0;
NSUInteger end = range.location;
NSRange temp = NSMakeRange(start,end);
range =[motherstr rangeOfString:sonstr options:NSBackwardsSearch range:temp];
}
總算解決了,寫的不咋滴,希望大家賜教...