简体   繁体   English

从变量目标c插入换行符

[英]Inserting a line break from a variable objective c

I am pulling data into my iphone application using xml. 我正在使用xml将数据提取到我的iphone应用程序中。 The xml value is then placed in a variable. 然后将xml值放在变量中。

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. 我希望换行符出现在标签中,而不是打印\\ 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? 有谁能解释一下?

您必须将子串\\n (由字符\\n )替换为实际的换行符(在\\n表示的C源代码中),例如使用NSString替换方法

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM