第一种: NSStringEncoding encoder = NSUTF8StringEncoding; NSString *file = [NSString stringWithContentsOfFile error:nil]; NSRange line; line.location = 0; line.length = 1; int length = [file length]; while (line.location <= length) { NSRange newLine = [file lineRangeForRange:line]; NSString *content = [file substringWithRange:newLine]; line.length = 1; line.location = newLine.location + newLine.length + 1; } - (NSString *)substringWithRange:(NSRange)aRange ----该函数会返回包含aRange的行 所以上面代码中content就得到每一行的内容了。 第二种: 读取一般性文档文件 NSString *tmp; NSArray *lines; lines = [[NSString componentsSeparatedByStr NSEnumerator *nse = [lines objectEnumerator]; // 读取<>里的内容 while(tmp = [nse nextObject]) { NSString *stringBetweenBrackets = nil; NSScanner *scanner = [NSScanner scannerWithString:tmp]; [scanner scanUpToString:@"<" intoString:nil]; [scanner scanString:@"<" intoString:nil]; [scanner scanUpToString:@">" intoString:&stringBetweenBrackets]; NSLog([stringBetweenBrackets description]); } |
iphone 读取 一行文件内…
最新推荐文章于 2016-08-31 16:09:11 发布