soleil
soleil

Reputation: 13073

iOS - new line character in UITextView

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.

Upvotes: 0

Views: 2375

Answers (1)

WhiteTiger
WhiteTiger

Reputation: 1691

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.

Upvotes: 2

Related Questions