我讀一個CSV文件到一個使用數組:爲什麼我的數組中的每個其他對象都是空白的?
NSString *theWholeTable = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"example" ofType:@"csv"]
encoding:NSUTF8StringEncoding
error:NULL];
NSArray *tableRows = [theWholeTable componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
以及陣列中每第二個對象是空的,任何想法,爲什麼?
CSV文件中的數據是這樣的: 10,156,326,614,1261,1890,3639,5800,10253,20914 20,107,224,422,867,1299,2501,3986,7047,14374
與10和20是開始每一條新線。
在此先感謝。
編輯 我嘗試使用下面的代碼來代替:
NSArray *tableRows = [theWholeTable componentsSeparatedByString:@"\n"];
這工作,我希望它太的方式。
雖然我仍然不確定爲什麼newlineCharacterSet創建空的對象......
您的CSV文件是否來自Windows計算機? – dasblinkenlight 2011-12-25 04:08:13