IPhone Reader File - Weird Behavior

so I have a file called answers.txtthat looks like this:

1:A
2:B
3:BC
......

so a bunch of lines separated by a new line

I use this code to get the lines in NSArray:

NSStringEncoding encoding;
NSError* error;
NSString* myString = [NSString stringWithContentsOfFile:filePath usedEncoding:&encoding error:&error];  
NSArray *lines = [myString componentsSeparatedByString:@"\n"];

The file is written in unix style, so the lines are separated \n, not\r\n

Now for the problem:

When I build on the simulator, I get the correct array of strings if I split into \r\nand the wrong array if I split it into \n(I mean it splits into \n, but then I split each row again in :, the second element has a new row in the end)

, ( \n, \r\n, - , , \r)

- ?

+3
1

, , , :

[str componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

.

+1

All Articles