IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnu ...
2012-10-16 16:20
537 查看
小结:
1)componentsSeparatedByString:截取指定字符串;
2) pathForResource:获取程序运行时目录
3) objectAtIndex:获取当前索引的字符串;
4) rangeOfString:获取指定短字符串在长字符串中的开始,结尾索引值;
5) stringWithContentsOfFile:按行读取文件
6) componentsSeparatedByString:@"\n"];换行分割字符串;
7) NSEnumerator *nse = [lines objectEnumerator];
将数组转换为NSEnumerator,可向前读取数据;
8) nextObject:读取下一行数据;
void splitString(){
NSString *animals =
@"dog#cat#pig";
//将#分隔的字符串转换成数组
NSArray *array = [animals
componentsSeparatedByString:@"#"];
NSLog(@"animals:%@",array);
//获取程序运行时目录
NSString *escapedPath = [[NSBundle
mainBundle] pathForResource:@"info"
ofType:@"plist"];
NSArray *strings = [escapedPath
componentsSeparatedByString:
@"/"];
NSString *tmpFilename = [strings
objectAtIndex:[strings
count]-1];
NSRange iStart = [escapedPath
rangeOfString : tmpFilename];
NSString *runtimeDirectory = [escapedPath
substringToIndex:iStart.location-1];
NSLog(@"runtimeDirectory:%@",runtimeDirectory);
//按行读取文件
NSString *tmp;
NSArray *lines = [[NSString
stringWithContentsOfFile:@"test.txt"
encoding:nil
error:nil]
componentsSeparatedByString:@"\n"];
NSEnumerator *nse = [lines
objectEnumerator];
while(tmp = [nse
nextObject]) {
NSLog(@"tmp:%@", tmp);
}
}
1)componentsSeparatedByString:截取指定字符串;
2) pathForResource:获取程序运行时目录
3) objectAtIndex:获取当前索引的字符串;
4) rangeOfString:获取指定短字符串在长字符串中的开始,结尾索引值;
5) stringWithContentsOfFile:按行读取文件
6) componentsSeparatedByString:@"\n"];换行分割字符串;
7) NSEnumerator *nse = [lines objectEnumerator];
将数组转换为NSEnumerator,可向前读取数据;
8) nextObject:读取下一行数据;
void splitString(){
NSString *animals =
@"dog#cat#pig";
//将#分隔的字符串转换成数组
NSArray *array = [animals
componentsSeparatedByString:@"#"];
NSLog(@"animals:%@",array);
//获取程序运行时目录
NSString *escapedPath = [[NSBundle
mainBundle] pathForResource:@"info"
ofType:@"plist"];
NSArray *strings = [escapedPath
componentsSeparatedByString:
@"/"];
NSString *tmpFilename = [strings
objectAtIndex:[strings
count]-1];
NSRange iStart = [escapedPath
rangeOfString : tmpFilename];
NSString *runtimeDirectory = [escapedPath
substringToIndex:iStart.location-1];
NSLog(@"runtimeDirectory:%@",runtimeDirectory);
//按行读取文件
NSString *tmp;
NSArray *lines = [[NSString
stringWithContentsOfFile:@"test.txt"
encoding:nil
error:nil]
componentsSeparatedByString:@"\n"];
NSEnumerator *nse = [lines
objectEnumerator];
while(tmp = [nse
nextObject]) {
NSLog(@"tmp:%@", tmp);
}
}
相关文章推荐
- iOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile等
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerato
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- IOS NSString 截取,objectAtIndex,rangeOfString
- 按字符串读取文件内容NSString stringWithContentsOfFile: (NSString类方法)
- obj-c iOS 数组存入程序文件 arrayWithContentsOfFile
- iOS imageNamed 与 imageWithContentsOfFile的区别
- ios 内存使用陷阱 和imageNamed 、imageWithContentsOfFile:(转)
- iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
- iOS学习笔记-- 加载图片选择imageNamed 方法还是 imageWithContentsOfFile
- ios imageWithContentsOfFile:path 图片不显示
- iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
- iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
- obj-c iOS 数组存入程序文件 arrayWithContentsOfFile
- iOS: NSData的方法dataWithContentsOfFile: