How to remove all of the html whitespace/newlines of a NSString

Posted by Kyriakos Leivadas on Stack Overflow See other posts from Stack Overflow or by Kyriakos Leivadas
Published on 2012-11-12T16:58:01Z Indexed on 2012/11/12 16:59 UTC
Read the original article Hit count: 240

Filed under:
|
|
|
|

i've got a problem and i hope someone can solve it.

I parsed some html to a nsstring and im trying to trim all of the characters and keep some specific words.

The problem is that i trimmed all the characters from the nsstring that i didnt want but the weird thing is that i cant get rid of all the whitespace.

i used all the techniques i read from other answers but still some whitespace remains.

here is my code

-(void)requestFinished:(ASIHTTPRequest *)request{

NSString *htmlData = [request responseString];

NSCharacterSet *garbage = [NSCharacterSet characterSetWithCharactersInString:@"qazwsxedcrfvtgbyhnujmik,ol.p;/[]'QAZWSXEDCRFVTGBYHNUJMIKOLP()\"-1234567890#{}=:+_&!`<>"]; //im doing this to remove all characters except non-english chars

htmlData = [htmlData compomentsSeparatedByCharactersInSet:garbage ]compomentsJoinedByString:@""];

htmlData = [htmlData stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

htmlData = [htmlData stringByReplacingOccurencesOfString:@"[\n\t\r ]+" withString@""];
htmlData = [htmlData stringByReplacingOccurencesOfString:@" " withString:@""];

NSLog(@"%@",htmlData); 

}

i get this result:

nonenglishwordsnonenglishwords

nonenglishwordsnonenglishwords

(whitespace or new lines in middle remains)

thank you.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about html