0

Reading in text from a data file. How can I get line breaks to work? I've tried \n, but it just puts "\n" into the string instead of creating a new line.

EDIT: The text is coming from a web service, which does not have true line breaks in the text.

soleil
  • 12,133
  • 33
  • 112
  • 183

1 Answers1

2

I do not understand your problem, doing it this way I get this result:

script to create the test file:

#!/bin/sh
(cat <<- EOF
i am
a
test file
EOF
) > /tmp/test.txt

objective c code:

NSString *str = [NSString stringWithContentsOfFile:@"/tmp/test.txt" encoding:NSASCIIStringEncoding error:nil];
NSLog(@"%@", str);

my output:

i am
a
test file

I hope you can be useful.

WhiteTiger
  • 1,691
  • 1
  • 18
  • 23
  • that would work in a basic text file, but the text is coming from a web service. I have edited my question to reflect this. – soleil Sep 08 '12 at 20:21
  • Going to accept this answer. The web service has a limitation of not allowing line breaks, so in this case there is no solution. – soleil Sep 14 '12 at 02:36