目标C语言-->
我有 cvs 文件,我想将它读入 NSString 并创建数组,即:
名称、州、价格、邮政编码
威斯康星州约翰,20000, 43555 .. ..
#import <Foundation/Foundation.h>
#import <string.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
//input user for a name on property list
int input;
NSLog(@"The worldcities.cvs contained infor on property names.");
NSLog(@"Enter a name: ");
scanf("%i", &input);
NSString *sourceFileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"filename" ofType:@"worldcities.csv"] encoding:NSUTF8StringEncoding error:nil];
NSMutableArray *csvArray = [[NSMutableArray alloc] init];
csvArray = [[sourceFileString componentsSeparatedByString:@"\n"] mutableCopy];
NSString *keysString = [csvArray objectAtIndex:0];
NSArray *keysArray = [keysString componentsSeparatedByString:@","];
[csvArray removeObjectAtIndex:0];
我希望能够根据来自 .cvs 文件的创建数组的用户输入输出属性名称,我将如何继续?