Duplicar posible:
Remove HTML Tags from an NSString on the iPhoneFranja de formularios de etiquetas HTML, etc de NSString
Me gustaría saber el mejor método para despojar a todo el HTML/Javascript, etc etiquetas a partir de una NSString.
La solución actual que estoy usando hojas comentarios y otras etiquetas en, ¿cuál sería la mejor manera de eliminarlos?
Sé de soluciones por ejemplo LibXML, pero me gustaría tener algunos ejemplos para trabajar.
solución actual:
- (NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim {
NSScanner *theScanner;
NSString *text = nil;
theScanner = [NSScanner scannerWithString:html];
while ([theScanner isAtEnd] == NO) {
// find start of tag
[theScanner scanUpToString:@"<" intoString:NULL] ;
// find end of tag
[theScanner scanUpToString:@">" intoString:&text] ;
// replace the found tag with a space
//(you can filter multi-spaces out later if you wish)
html = [html stringByReplacingOccurrencesOfString:
[ NSString stringWithFormat:@"%@>", text]
withString:@""];
}
// trim off whitespace
return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
}
@ x3ro por lo votan para cerrarla como un duplicado – Mark
@ Marcos lo hizo, ese comentario es añadido automáticamente (para el beneficio del póster) cuando una persona vota para cerrar. – benzado
Hmm la estrecha recuento seguía siendo cero cuando lo vi – Mark