程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> xcode-在iPhoneSDK中刪除指定HTML標簽

xcode-在iPhoneSDK中刪除指定HTML標簽

編輯:編程綜合問答
在iPhoneSDK中刪除指定HTML標簽

應用中的NSString中包含HTML,我想刪除< img src=..../>標簽的內容。

舉個例子:

Source = < p>< a href="http://wpcore.mpf.s3.amazonaws.com/wp-content/uploads/2012/12/thumbs_img_0500.jpg">**< img class="alignleft size-full wp-image-4730" style="margin-left: 5px; margin-right: 5px;" title="thumbs_img_0500" src="http://wpcore.mpf.s3.amazonaws.com/wp-content/uploads/2012/12/thumbs_img_0500.jpg" alt="thumbs img 0500" width="120" height="120" />**< /a>The two professional level < a title="3d printing" href="http://www.makepartsfast.com/category/products/3d-printers/">3D printers< /a> that build parts in color are the Zprinter from 3D Systems and the < a href="http://www.makepartsfast.com/2012/05/3812/mcor-announces-full-3d-color-3d-printer">Iris< /a> from Mcor Technologies. Earlier this year, Mcor Technologies announced its Iris full color 3D printer at the Rapid show and recently at Euromold. The Zprinter uses ink jetted into the build powder. The Iris, however, uses a different technique for creating color parts. Dr. Conor MacCormack, CEO of Mcor, discusses this technology.</p>
< p>< a href="http://wpcore.mpf.s3.amazonaws.com/wp-content/uploads/2012/12/MacCormack-part-1.mp3">MacCormack part 1< /a>< /p>

其中 img src 標簽都不同。怎麼實現呢?
我的代碼:

-(void)viewWillAppear:(BOOL)animated
{
source = [NSString stringWithFormat:@"%@",[[self.parseResults objectAtIndex:k] objectForKey:@"summary"]];

NSLog(@"%@",source);
}

最佳回答:


可以實現代碼:

-(void)viewWillAppear:(BOOL)animated
{
 source = [NSString stringWithFormat:@"%@",[[self.parseResults objectAtIndex:k] objectForKey:@"summary"]];
 Source=[self flattenHTML:Source];//call flattenhtml method...
 NSLog(@"%@",source);
}


#pragma mark ---Removing HTML Tags
- (NSString *)flattenHTML:(NSString *)html {

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

while ([theScanner isAtEnd] == NO) {

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

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

}
html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

return html;
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved