Best way to clean HTML str in ObjC
Best way to clean HTML str in ObjC
- Subject: Best way to clean HTML str in ObjC
- From: malcom <email@hidden>
- Date: Thu, 25 May 2006 11:24:06 +0200
hi, what's the best way to replace html chars (  etc.) in a
NSString? i've used [str replaceOccurrencesOfString... for each html
code but I don't know if it's the fast method.
something like this:
+ (void) replaceChrs:(NSMutableString *) str {
[str replaceOccurrencesOfString: @"<<" withString:@"\"" options:
NSCaseInsensitiveSearch range: NSMakeRange(0,[str length])];
[str replaceOccurrencesOfString: @">>" withString:@"\"" options:
NSCaseInsensitiveSearch range: NSMakeRange(0,[str length])];
....
....
while I've used this method to clean html from <> tags but it should be fine:
+ (NSString *) cleanTags:(NSString *) mut {
NSMutableString *dest = [[NSMutableString alloc] initWithString:mut];
[self replaceChrs: dest];
int k;
int start = -1;
int end = -1;
for (k=[dest length]-1; k > -1 ;k--) {
char c = [dest characterAtIndex:k];
if (c == '<') start = k;
if (c == '>') end = k+1;
if (start > -1 && end > -1) {
[dest deleteCharactersInRange: NSMakeRange(start,end-start)];
start = end = -1;
}
}
return [dest autorelease];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden