• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Best way to clean HTML str in ObjC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 (&#32 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


  • Prev by Date: Alternatives to NSMatrix and NSTable?
  • Next by Date: Re: Best(simplest) way to implement iTunes like "link" buttons/icons
  • Previous by thread: Re: Alternatives to NSMatrix and NSTable?
  • Next by thread: beginSheet
  • Index(es):
    • Date
    • Thread