关于iphone的一个简单问题
我的字符串是k=/Users/applefan/Library/Application Support/iPhone Simulator/3.1.3/Applications/422B3239-F521-4985-89FE-EC778C57C0AB/Documents/1.sql 现在,如何从1.sql获取1 我做过这样的事关于iphone的一个简单问题,iphone,nsscanner,Iphone,Nsscanner,我的字符串是k=/Users/applefan/Library/Application Support/iPhone Simulator/3.1.3/Applications/422B3239-F521-4985-89FE-EC778C57C0AB/Documents/1.sql 现在,如何从1.sql获取1 我做过这样的事 NSScanner *scanner = [NSScanner scannerWithString:storePath]; [sca
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/之后的数值,我们需要更多关于您的具体情况的信息。如果每次字符串的格式都完全相同,则只需执行
[NSString stringByRemovingOcurrencesOfString:withString:]代码>如果比这稍微复杂一点,我们可以研究其他选项。我只需要Documents/后面的数字值,不管值是什么
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);