开发者

How to print a string in a proper format if my string is having new line character in objective c

开发者 https://www.devze.com 2023-04-12 12:50 出处:网络
I am having an issue with this piece of code: NSStri开发者_运维问答ng *msg=[[TBXML valueOfAttributeNamed:@\"msg\" forElement:root] ];

I am having an issue with this piece of code:

NSStri开发者_运维问答ng *msg=[[TBXML valueOfAttributeNamed:@"msg" forElement:root] ];  
lblText.text=msg;

The variable msg contains the string "Good Job\nThanks". When I assign 'msg' to the label text property, the string is shown with the newline character \n but I would like the string to be displayed like this instead:

Good Job

Thanks

/shivam


As your string seems to come from a XML file, try to enter the XML's New Line character 
 instead of \n. Otherwise it will print the characters \and n.


Try to set number of lines that label could have to unlimited number:

UILabel *label;
label.numberOfLines = 0;`
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号