2011-09-01 73 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

確定非常感謝 –