2011-09-01 59 views
1
NSString *labelText = @"Choose a topic from the left to find answers for your questions about iPhone. For the latest downloads, manuals, and other resources for iPhone, choose an option below."; 
NSLog(@"Label Text:--->%@",labelText); 

所以我的问题是,我想要搜索iPhone文本无论在上面的nsstring中显示,并且如果可能的话,也请获取位置,所以请给我任何想法或任何链接来开发此功能。NSString中的多重搜索

回答

1

拿在这里:(NSLog将打印substring位置的指标在source字符串)

- (void)findAllLocationsOfString:(NSString *)substring sourceString:(NSString *)source 
{ 
    NSRange searchRange = NSMakeRange(0, [source length]); 
    NSRange place = NSMakeRange(0, 0); 
    while (searchRange.location < [source length]) 
    { 
     place = [source rangeOfString:substring options:NSLiteralSearch range:searchRange]; 
     if (place.location != NSNotFound) NSLog(@"found here : %d", place.location); 
     searchRange.location = place.location + place.length; 
     searchRange.length = [source length] - searchRange.location; 
    } 
} 
+0

非常感谢任何想法来设定在得到搜索字符串 –

+0

提出新课题新问题添加按钮框,请 – Nekto

+0

确定非常感谢 –