NSScanner关于iphone的简单问题

时间:2011-01-28 09:57:29

标签: iphone nsscanner

我的字符串是k = / Users / applefan / Library / Application Support / iPhone Simulator / 3.1.3 / Applications / 422B3239-F521-4985-89FE-EC778C57C0AB / Documents / 1.sql < / p>

现在如何从1.sql

获取 1

我做了这样的事情

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

我也这样做了

unsigned int intValue;

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

它给了我所有的int值**

但我只想要 / Documents /

之后的数值

1 个答案:

答案 0 :(得分:2)

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);