Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a line break from a variable objective c

I am pulling data into my iphone application using xml. The xml value is then placed in a variable.

example variable:

123 London road \n London \n England

The variable is then set as a label.

I want the line breaks to appear in the label, instead it is printing \n.

If i manually set the label value

locationLabel.text = @"123 London road \n London \n England"

It works as i want it to.

Can anyone explain this?

like image 765
user337174 Avatar asked Apr 13 '26 13:04

user337174


1 Answers

You have to replace the substrings \n (consisting of the characters \ and n) with the actual linebreak character (in C-sources expressed by \n), e.g. by using NSStrings replace methods:

NSString *res = [myStr stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
like image 110
Georg Fritzsche Avatar answered Apr 16 '26 04:04

Georg Fritzsche