从可变目标c插入换行符 [英] Inserting a line break from a variable objective c
本文介绍了从可变目标c插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用xml将数据提取到我的iPhone应用程序中.然后将xml值放入变量中.
I am pulling data into my iphone application using xml. The xml value is then placed in a variable.
示例变量:
123 London road \n London \n England
然后将该变量设置为标签.
The variable is then set as a label.
我希望换行符出现在标签中,而是打印\ n.
I want the line breaks to appear in the label, instead it is printing \n.
如果我手动设置标签值
locationLabel.text = @"123 London road \n London \n England"
它按我的意愿工作.
有人可以解释吗?
推荐答案
您必须将子字符串\n
(由字符\
和n
组成)替换为实际的换行符(在C语言中表示)通过\n
),例如通过使用NSString
的替换方法:
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 NSString
s replace methods:
NSString *res = [myStr stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
这篇关于从可变目标c插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文