替换< br>在带有新行的NSString中 [英] Replace <br> in an NSString with a new line

查看:44
本文介绍了替换< br>在带有新行的NSString中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的 NSString

NSString * string = @"textTextTextTextText< br> textTextTextText< br> TextTextText"

我想将此 NSString 设置为我的 UICell 的文本,并在该字符串上的每个
标记上换行.我该怎么办?

I want to set this NSString to be the text of my UICell with a new line on each
tag found on the string. How could I do that?

我已经尝试过了,但是没有成功:

I've tried this, without success:

cell.textLabel.text = [[文本componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@< br>"];

推荐答案

怎么样:

string = [string stringByReplacingOccurrencesOfString: @"<br>" withString: @"\n"]

或者,如果您使用的是Swift Strings

or, if you're using Swift Strings

var string = "textTextTextTextText<br>textTextTextText<br>TextTextText"
string = Array(string).reduce("") {$0 + ($1 == "<br>" ? "\n" : $1)}

这篇关于替换&lt; br&gt;在带有新行的NSString中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆