私はiPhone開発の初心者で、HTMLデータを文字列形式に変換しようとしています。現在、これを実現するためにstringByConvertingHTMLToPlainTextを使用していますが、HTMLのフォーマットは無視されます。変換しているHTMLデータには改行がありますが、stringByConvertingHTMLToPlainTextはHtMLタグのみを削除し、結果の文字列をフォーマットしません。どんな助けでも大歓迎です。
私のコード:
NSString *temp = [[[stories objectAtIndex: storyIndex] objectForKey: @"summary"]stringByConvertingHTMLToPlainText];
HTMLデータ:
Holiday Inn<br/>Dedham,MA<br/>Sun May 5th 2013-Sun May 5th 2013<br/>Contact: Harry Tong at 603-978-3459<p><sub><i>-- Delivered by <a href="http://feed43.com/">Feed43</a> service</i></sub></p>
結果の文字列:
Holiday InnDedham,MASun May 5th 2013-Sun May 5th 2013Contact: Harry Tong at 603-978-3459-- Delivered by "http://feed43.com/"Feed43 service
私は欲しい:
Holiday Inn
Dedham,MA
Sun May 5th 2013-Sun May 5th 2013
Contact: Harry Tong at 603-978-3459
-- Delivered by "http://feed43.com/"Feed43 service
編集
NSString *html = [[stories objectAtIndex: storyIndex] objectForKey: @"summary"];
NSString *text = [html stringByReplacingOccurrencesOfString:@"<br/>" withString:@" \n "];
NSString *temp = [text stringByConvertingHTMLToPlainText];