Reputation: 3402
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);
So my issue is that I want to search iPhone text wherever is display in above nsstring and also get position if possible so please give me any idea or any link to develop this functionality.
Upvotes: 0
Views: 461
Reputation: 17877
Take it here: (NSLog
will print indexes of your substring
positions in source
string)
- (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;
}
}
Upvotes: 1