转换HTML字符串

时间:2012-02-24 07:03:07

标签: iphone html

这可能是一个简单的问题,但我无法从下面的字符串中获取确切的数据。 我希望提取数据,但我无法做到这一点。 1.描述 2.当文字 3.文本 4.点击此处链接

如何在目标C中转换它。

<p>
    <a href="http://feedads.g.doubleclick.net/~a/uD33rOAaHkAZywKvO6ntrkv_ETU/0/da">
        <img src="http://feedads.g.doubleclick.net/~a/uD33rOAaHkAZywKvO6ntrkv_ETU/0/di" border="0" ismap="true"></img>
    </a>
<br/>
    <a href="http://feedads.g.doubleclick.net/~a/uD33rOAaHkAZywKvO6ntrkv_ETU/1/da">
        <img src="http://feedads.g.doubleclick.net/~a/uD33rOAaHkAZywKvO6ntrkv_ETU/1/di" border="0" ismap="true"></img>
    </a>
</p>


<p>
    <a href="http://mumbai.burrp.com/events/little-theatre-ncpa_semshook_nariman-point_mumbai/19313517316">
        <img src="/images/evt/c/6/photo_little-theatre-ncpa_nariman-point_mumbai@c6s6kwyg_2wat_1_300.jpg"/>
    </a>
</p>                


<p>
    Tenzin is a Tibetan born and raised in India. Yearning to explore his true homeland, he impulsively hops on his motorcycle and embarks on a personal quest: to find his identity and discover the indescribable beauty and wonders of his magnificent homeland. But Tibet is a nation under siege from a repressive regime. While Tenzin encounters friendship, camaraderie and even love along the way, he cannot escape the horrors of a political world he wants no part of. Looking only for the way to peace, both within himself and for the land he loves, Tenzin must find the courage to pursue the truth, even if it means facing terrible dangers to find his Semshook.
<strong>Language</strong>: Hindi, English, Tibetan Film with English subtitles
<strong>Directed by</strong>: Siddharth Anand Kumar
<strong>Cast</strong>: Tenzin Younden, Tenzin Choedon and Tensin Woebhum
</p>

<p>
    <strong>When:</strong> Friday Feb, 24
</p>    

<p>
    <strong>Where:</strong> Little Theatre (NCPA), Nariman Poin
</p>

<p>
    <a href="http://mumbai.burrp.com/events/index.html">More events</a> in Mumbai
</p>

<p>
    <a href="http://mumbai.burrp.com/events/date/this-weekend">Click Here</a> to view more events happening <strong>this weekend</strong> in Mumbai
</p>

我使用过这段代码,但是这给了我纯文本,我希望与该文本相关的链接就像文本和链接组合一样。

NSScanner *theScanner;
    NSString *text = nil;
    theScanner = [NSScanner scannerWithString:html];

    while ([theScanner isAtEnd] == NO) {

        [theScanner scanUpToString:@"<" intoString:NULL] ; 

        [theScanner scanUpToString:@">" intoString:&text] ;

        html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>", text] withString:@""];
    }
    //
    html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSLog(@"html======================>%@",html);
    return html;

1 个答案:

答案 0 :(得分:0)

使用XML Parsing和NSString方法的组合。