(ios)CSV文件到多个阵列?
好的,我正在学习使用xCode5,我想使用csv文件截图来读取数据并存储到7个单独的数组中。但是,我在分离7个值时遇到问题。我知道在我的例子中,我应该使用字符串分隔的组件,…但是我知道应该放在哪里。任何建议都将不胜感激 csv屏幕截图: *第7个值为,用于其他目的 {(ios)CSV文件到多个阵列?,ios,arrays,csv,Ios,Arrays,Csv,好的,我正在学习使用xCode5,我想使用csv文件截图来读取数据并存储到7个单独的数组中。但是,我在分离7个值时遇到问题。我知道在我的例子中,我应该使用字符串分隔的组件,…但是我知道应该放在哪里。任何建议都将不胜感激 csv屏幕截图: *第7个值为,用于其他目的 { }这应该可以做到: for(int i = 0; i < [rows count]; i++) { NSArray *arrayLine = [[row objectAtIndex:i] componentsSepa
}这应该可以做到:
for(int i = 0; i < [rows count]; i++)
{
NSArray *arrayLine = [[row objectAtIndex:i] componentsSeparatedByString@","];
[_names addObject:[arrayLine objectAtIndex:0]];
[_origins addObject:[arrayLine objectAtIndex:1]];
[_ages addObject:[arrayLine objectAtIndex:2]];
[_heights addObject:[arrayLine objectAtIndex:3]];
[_weights addObject:[arrayLine objectAtIndex:4]];
[_games addObject:[arrayLine objectAtIndex:5]];
[_images addObject:[arrayLine objectAtIndex:6]];
}
但在你的图像中,我没有看到第7个值,如果它不存在,可能会崩溃。好吧,你说第七个值是,所以你可能想管理它。这非常有效!我还将第7个值更改为N/A,以便以后不会出现问题。非常感谢。
for(int i = 0; i < [rows count]; i++)
{
NSArray *arrayLine = [[row objectAtIndex:i] componentsSeparatedByString@","];
[_names addObject:[arrayLine objectAtIndex:0]];
[_origins addObject:[arrayLine objectAtIndex:1]];
[_ages addObject:[arrayLine objectAtIndex:2]];
[_heights addObject:[arrayLine objectAtIndex:3]];
[_weights addObject:[arrayLine objectAtIndex:4]];
[_games addObject:[arrayLine objectAtIndex:5]];
[_images addObject:[arrayLine objectAtIndex:6]];
}