我有NSString
这样的
NSString *string = @"textTextTextTextText<br>textTextTextText<br>TextTextText"
我想将此NSString
设置为UICell
的文本,并在字符串上找到的每个标签上添加一个新行。我怎么能这样做?
我试过这个,没有成功:
cell.textLabel.text = [[text componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@"<br>"];
答案 0 :(得分:12)
怎么样:
string = [string stringByReplacingOccurrencesOfString: @"<br>" withString: @"\n"]
或者,如果您使用的是Swift Strings
var string = "textTextTextTextText<br>textTextTextText<br>TextTextText"
string = Array(string).reduce("") {$0 + ($1 == "<br>" ? "\n" : $1)}
答案 1 :(得分:2)
NSString * result =
[string stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
答案 2 :(得分:0)
SWIFT 5: 如果您使用的是Swift字符串(可以将NSString转换为String):
df2