Friday, 16 November 2012

Substring with string location.

see something like this srting to get string then this is code for get string from fullstring

- (NSString *)extractString:(NSString *)fullString toLookFor:(NSString *)lookFor skipForwardX:(NSInteger)skipForward toStopBefore:(NSString *)stopBefore 
          NSRange firstRange = [fullString rangeOfString:lookFor]; 
          NSRange secondRange = [[fullString substringFromIndex:firstRange.location + skipForward] rangeOfString:stopBefore];
          NSRange finalRange = NSMakeRange(firstRange.location + skipForward, secondRange.location);
         return [fullString substringWithRange:finalRange];

use this method like bellow..

 NSString *strTemp = [self extractString:@"" toLookFor:@"www" skipForwardX:0 toStopBefore:@"ab"];
    NSLog(@"\n\n Substring ==>> %@",strTemp);

No comments:

Post a Comment