IOS NSString 截取,objectAtIndex,rangeOfString
2013-05-23 17:15
381 查看
转自:http://www.189works.com/article-80848-1.html
摘要: @import url(http://www.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);小结:1)componentsSeparatedByString:截取指定字符串;2)pathForResource:获取程序运
...
摘要: @import url(http://www.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);小结:1)componentsSeparatedByString:截取指定字符串;2)pathForResource:获取程序运
...
小结: 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等
- 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,NSEnu ...
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- IOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerato
- iOS NSString 截取,objectAtIndex,rangeOfString,stringWithContentsOfFile,NSEnumerator
- IOS成长之路-Nsstring中搜索方法rangeOfString
- IOS成长之路-Nsstring中搜索方法rangeOfString
- IOS成长之路-Nsstring中搜索方法rangeOfString
- iOS 判断字符串中含有某个字符串 rangeOfString
- Android Studio 2.0+发布APK出现ExternalSystemException: String index out of range: -123错误
- String index out of range: 0
- Hibernate query.list()查询发生java.lang.StringIndexOutOfBoundsException: String index out of range: 0错误
- java.lang.StringIndexOutOfBoundsException: String index out of range: 0错误的原因 3ff0
- IOS NSString比较,截取,NSLog,NSRang,isEqualToString,stringWithFormat
- Hibernate query.list()查询发生java.lang.StringIndexOutOfBoundsException: String index out of range: 0错误
- Android Studio Error String index out of range 0 字符串索引超出范围