Just to give context to my problem, I often have to run search and replace on CSV files. I would like to start doing this by coding my needs in Objective-C and then run the executable to get the job done.
I currently have this chunk of code to open a file and stick it’s contents into a string. I then compile it in terminal and then run it.
Here is the code of the entire program:
#import <Foundation/Foundation.h>
int main (int argc, const char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Running....");
NSString* filePath = @"/Users/xxxxxx/Desktop/test_level2.txt";
NSString* fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSLog(@"file contents --->%@", fileContents);
[pool drain];
return 0;
}
The weird thing about this is that it prints only some of the contents of the file. Out of 20 lines, it prints the first and the last and some random parts from the middle.
Any idea of how I can solve this? Any suggests of how I can get the entire contents of the file into an NSString?
You sure there’s not some carriage returns rather than new lines in there?
Does it do the same thing when you do
cat /Users/xxxxxx/Desktop/test_level2.txt?