Reputation: 511
I am trying to find the Regular expression to extract a part of my string from the Entire sub string .Feel free to suggest me a best Way .
so here is the case , i can get any Eamil so lets say [email protected] , or something similar , i want to remove just the Username that is "abd" and save into another string.
Upvotes: 1
Views: 1545
Reputation: 4254
I don't think you'll need regular expressions for that. Just do this:
NSString* email = @"[email protected]";
NSArray * components = [email componentsSeparatedByString:@"@"];
NSString* username = (NSString *)[components objectAtIndex:0];
you alsa can do:
NSString* email = @"[email protected]";
NSString* username = [email substringToIndex:[email rangeOfString:@"@"].location];
Upvotes: 5