1

私は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];
4

2 に答える 2

1

<br/> (および古い html の場合は <br> ) を改行文字に置き換えるだけでよいと思います。プログラミングしている言語の改行文字を Google で検索し、文字列置換関数を使用します。

于 2013-03-11T22:10:04.840 に答える