NSString *str = @" hello i am emp 1313 object of string class 123";
NSScanner *scanner = [NSScanner scannerWithString:str];
// set it to skip non-numeric characters
[scanner setCharactersToBeSkipped:
[[NSCharacterSet decimalDigitCharacterSet]
invertedSet]];
int i;
while ([scanner scanInt:&i])
{
NSLog(@"Found int: %d",i);
}
// reset the scanner to skip numeric characters
[scanner setScanLocation:0];
[scanner setCharactersToBeSkipped:
[NSCharacterSet decimalDigitCharacterSet]];
NSString *resultString;
while ([scanner scanUpToCharactersFromSet:
[NSCharacterSet decimalDigitCharacterSet]
intoString:&resultString]) {
NSLog(@"Found string: %@",resultString);
}
No comments:
Post a Comment