I wants to extract substring from NSString. How it is possible.
Example : String is abcdefwww.google.comabcdef
output : www.google.com
In the main String, It is not predefined which url comes, It may be google.com or yahoo.com etc.
So I have to find the Start location of w in www and the the last location of m in .com.
So my question is that how I can find the start location of w in www and the location of m in .com, so i extract this part
Edited due to issue :
How we can extract www.mywebsite.co.uk from this string asdfwww.mywebsite.co.ukasdfajsf
Thanks
substring from string like bellow
- (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 + [stopBefore length]);
return [fullString substringWithRange:finalRange];
}
use this method like below...
NSString *strTemp = [self extractString:@"abcdefwww.google.comabcdef" toLookFor:@"www" skipForwardX:0 toStopBefore:@".com"];
NSLog(@"\n\n Substring ==>> %@",strTemp);
for more information see bellow link..
help-needed-function-extract-string-string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With