码迷,mamicode.com
首页 > 其他好文 > 详细

CSV解析

时间:2015-07-26 17:07:08      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

NSString *path = [[NSBundle mainBundle] pathForResource:
                      @"type" ofType:@"csv"];
    NSString* fileContents =
    [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding error:nil];
// first, separate by new line
NSArray* allLinedStrings =
[fileContents componentsSeparatedByString:@"\r\n"];

// then break down even further
_poiTypes = [[NSMutableDictionary alloc] initWithCapacity:[allLinedStrings count]];
for (int i = 0; i NSString* strsInOneLine =
[allLinedStrings objectAtIndex:i];
NSString *trimmedString = [strsInOneLine stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSArray* singleStrs =
[trimmedString componentsSeparatedByString:@","];
NSString *strType = [singleStrs objectAtIndex:0];
NSString *strValue = [singleStrs objectAtIndex:1];
NSString *strValue1 = [strValue substringToIndex:[strValue length]-2];
[_poiTypes setObject:strType forKey:strValue1];

}

}

CSV解析

标签:

原文地址:http://www.cnblogs.com/wcLT/p/4677972.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!