首页 > 其他 > 详细

CSV解析

时间:2015-07-26 17:04:05      阅读:183      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!