Let us say I have this NSString
: @"Country Address Tel:number"
.
How can I do to get the substring that is before Tel
? (Country Address )
And then How can I do to get the substring that is after Tel
? (number)
Use NSScanner:
NSString *string = @"Country Address Tel:number";
NSString *match = @"tel:";
NSString *preTel;
NSString *postTel;
NSScanner *scanner = [NSScanner scannerWithString:string];
[scanner scanUpToString:match intoString:&preTel];
[scanner scanString:match intoString:nil];
postTel = [string substringFromIndex:scanner.scanLocation];
NSLog(@"preTel: %@", preTel);
NSLog(@"postTel: %@", postTel);
NSLog output:
preTel: Country Address
postTel: number
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