Reputation: 569
I have an NSString
like this
NSString *string = @"textTextTextTextText<br>textTextTextText<br>TextTextText"
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 = [[text componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@"<br>"];
Upvotes: 3
Views: 9418
Reputation: 43
SWIFT 5: If you are using Swift string (you can transform your NSString to String):
var string = "line1<br>line2<br>line3"
string = string..replacingOccurrences(of: "<br>", with: "\n"))
Upvotes: 0
Reputation: 53181
How about:
string = [string stringByReplacingOccurrencesOfString: @"<br>" withString: @"\n"]
or, if you're using Swift Strings
var string = "textTextTextTextText<br>textTextTextText<br>TextTextText"
string = Array(string).reduce("") {$0 + ($1 == "<br>" ? "\n" : $1)}
Upvotes: 13
Reputation: 104698
NSString * result =
[string stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
Upvotes: 2