我嘗試從URL中獲取一些文本並將其放在UITextView
中。 那我在ViewController
代碼:如何刪除那些行,當我從URL獲取文本?
NSString *urlString = @"http:/...";
NSError *error = nil;
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString] options:kNilOptions error:&error];
if (error)
NSLog(@"%s: dataWithContentsOfURL error: %@", __FUNCTION__, error);
else
{
NSString *result = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"%s: result = %@", __FUNCTION__, result);
// if you were updating a label with an `IBOutlet` called `resultLabel`, you'd do something like:
self.mytextview.text = result;
}
現在模擬器顯示了我的觀點,即文本:
對不起,文字是德國:)現在
我怎麼能隱藏或刪除HTML,頭,身體等?
嘿Sebyddd,謝謝。上述解決方案工作正常。我也會嘗試你的。 – Mehmet63 2014-09-02 18:10:52
當然,如果您使用的是UIWebView,您可以使用@ fic的解決方案,但如果您正在下載網頁的內容,我看不到任何理由。 – Sebyddd 2014-09-02 18:13:46
我試過了,我喜歡你的解決方案,但它顯示標題也是「PHP-Test」。我只想要「p」之間的文本。我該如何處理? – Mehmet63 2014-09-02 18:22:21