Reputation: 1263
I have set of questions stored in SQLite database. For mathematics subject those are stored as formula/equations in html format. I retrieve question and stored it as string:
NSString *htmlstring = @"If 3<em>x</em><sup><strong>2</strong></sup> + 11<em>x</em> + 6 $$\\ge$$ 0, then <em>x</em> $$\\in $$";
To display this string in UILabel, I use following piece of code :
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
questionLbl.attributedText = attrStr;
This code not worked as expected and output is:
The expected output is:
I didn't understand where its going wrong, while fetching data from database or converting html to plain text.
UPDATE
From Ashmi's answer below I figured out the text is in Latex format. How can we convert latex command to symbol is now a question. There are 3 possibilities:
Upvotes: 1
Views: 548
Reputation: 710
Please check below code your HTML format may be not correct So I just change HTML format and get output you want. For more information to make Math symbol in HTML please check below link.
https://www.univie.ac.at/moe/formeln.html
NSString *htmlstring = @"If 3<em>x</em><sup><strong>2</strong></sup> + 11<em>x</em> + 6 ≥0, then <em>x</em>€";
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlstring dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
NSLog(@"%@",attrStr.string);
Upvotes: 3