0

I am getting a string like this <b><i>Hello there </i></b> but in HTML format. This string is supposed to be bold and italicised. How would i convert this into "Hello there" and store it in a string to be used later on. Would i need to do something like HTML parsing?

1 Answer 1

1

To store it you'd just assign it to a variable like:

NSString *helloWorldString = @"<b><i>Hello there </i></b>";

Later on, when you want to use it in a UILabel you can do something like this:

NSError *error = nil;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 500, 100)];
label.attributedText =
[[NSAttributedString alloc]
          initWithData: [helloWorldString dataUsingEncoding:NSUTF8StringEncoding]
               options: @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}
    documentAttributes: nil
                 error: &error];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.