读取'CSV'文件 - 无法读取包含loong字符串的csv文件 [英] Reading 'CSV' file - Cannot read csv file contains loong string
问题描述
我使用以下方法来读取.csv文件。它适用于包含普通字符串,数字等的csv文件。
I am using following method to read .csv file. It is working fine for csv files which contains normal strings, numbers ect.
但它无法读取包含长字符串的csv文件(例如:5,6行的描述) 。
But it fails to read csv files contains long strings (eg: description of 5,6 lines).
是否存在此类技术难题?非常感谢您的帮助。
Is there is such technical difficulty? Your help is highly appreciated.
-(void)readTitleFromCSV:(NSString*)path AtColumn:(int)column
{
//arrBreeds = [[NSMutableArray alloc]init];
NSMutableArray *arrTemp = [[NSMutableArray alloc]init];
NSString *fileDataString=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *linesArray=[fileDataString componentsSeparatedByString:@"\n"];
// preparing array with questions and answers
for(int i=0; i<[linesArray count];i++){
[arrTemp addObject:[[linesArray objectAtIndex:i] componentsSeparatedByString:@","] ];
}
NSLog(@"ArrBreeds %@", arrTemp);
}
推荐答案
你是首先根据换行符将文本与CSV文件分开,然后分离组件。发生这样的事情:
You are first separating the text from your CSV file based on line break and then separating the components. This happens something like this:
absd,sgsgs
dfdf,dfghj
absd,sgsgs dfdf,dfghj
这里你应该得到解析后有3个对象,但是用你的代码得到4个。
Here you should get 3 objects after parsing , but with your code you will get 4.
你可以继续这样做:
NSArray *linesArray=[fileDataString componentsSeparatedByString:@","];
这篇关于读取'CSV'文件 - 无法读取包含loong字符串的csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!