Insert line break from target variable c

I am extracting data to my iphone application using xml. Then the xml value is placed in the variable.

variable example:

123 London road \n London \n England

Then the variable is set as a label.

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

If I manually set the label value

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

It works the way I want.

Can anyone explain this?

+3
source share
1 answer

You must replace the substrings \n(consisting of \and n) with the actual character of the string (in C-sources expressed by the character \n), for example. using NSString replace methods :

NSString *res = [myStr stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
+7

Source: https://habr.com/ru/post/1746252/


All Articles