I am new to Xcode and was wondering if anyone could help me with this.
I need to make an application that is able to open a file and replace its contents.
E.g. (in psuedo code)
Replace(“String1”, “String2”, “~/Desktop/Sample.txt”)
Please let me know if I’m not clear enough.
Thanks in advance.
You probably want this
And regarding your question about how to read the text from a file to a NSString:
And for writing to a file:
(using the same NSString from loading: stringFromFile)
Note that in this example i use an encoding for windows (this means it uses charcters \n\r at the end of each line). Check the documentation for other types of encoding.
(See
NSStringdocumentation)