CSV解析

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];

}

}
posted @   小毛驴  阅读(366)  评论(0编辑  收藏  举报
编辑推荐:
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
阅读排行:
· 用 DeepSeek 给对象做个网站,她一定感动坏了
· DeepSeek+PageAssist实现本地大模型联网
· 手把手教你更优雅的享受 DeepSeek
· Java轻量级代码工程
· 从 14 秒到 1 秒:MySQL DDL 性能优化实战
点击右上角即可分享
微信分享提示