Weird problem with NSString initWithContentsOfFile

I have a .csv file in my bundle which I need to parse into an NSArray. The problem is when I init an NSString with contents of file (the file is located in my bundle), it returns nil. However, if I change the contents of the file, to anything else (random), it works. Is it possible there's some sort of string/character in the file that might be messing with the initialization?

It's just a simple csv file with 2 columns, a number, a comma, some text and "\n".

Thanks.

Answers


CSV => NSArray?

https://github.com/davedelong/CHCSVParser

*disclaimer: I wrote it.


Works for me:

NSStringEncoding usedEncoding = 0;
NSError *csvError = nil;
NSString *raw = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://pastebin.com/raw.php?i=RXPPwpvy"] usedEncoding:&usedEncoding error:&csvError];
NSLog(@"raw: %@", raw);
NSLog(@"%@", [NSArray arrayWithContentsOfCSVString:raw encoding:usedEncoding error:&csvError]);

Need Your Help

GridView ItemClick navigate to another page and show details about the clicked item Windows store app

c# vb.net xaml windows-store-apps

i have a GridView with item from a list of person list, how can i show details of the clicked item in the next page?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.