NSScanner simple question on iphone

451 views Asked by At

my string is k= /Users/applefan/Library/Application Support/iPhone Simulator/3.1.3/Applications/422B3239-F521-4985-89FE-EC778C57C0AB/Documents/1.sql

now how to get 1 from 1.sql

i did somethins like this

            NSScanner *scanner = [NSScanner scannerWithString:storePath];
        [scanner scanUpToString:@".sql" intoString:&k]  ;           
            NSLog(@"test is %@",k);

i did this also

unsigned int intValue;

                while([scanner isAtEnd] == NO) {
                    [scanner scanHexInt:&intValue];
                    NSLog(@"HEX : %d", intValue);       
                **}

it gives me all the int value**

but i only want the numeric value after /Documents/

1

There are 1 answers

0
Hoang Pham On BEST ANSWER
NSString *k = @"/Users/applefan/Library/Application Support/iPhone Simulator/3.1.3/Applications/422B3239-F521-4985-89FE-EC778C57C0AB/Documents/1.sql";
NSString *one = [[[[k componentsSeparatedByString:@"Documents/"] objectAtIndex:1] 
   componentsSeparatedByString:@".sql"] objectAtIndex:0];
NSLog(@"Is it one? %@", one);