Many thanks for your reply. Wouldn't using these methods be a lot more expensive (and slower) than going through using -characterAtIndex: or something similar, accessing the characters directly, though? I'm thinking that I would have to add every character to the character set and then let NSString deal with all the underlying character stuff this way, whereas if I could check the unicode char is within a range then it would be faster. I could be entirely wrong though, which is why I'm asking. :)
Thanks again and all the best, Keith --- On Thu, 1/28/10, Jens Alfke <j...@mooseyard.com> wrote: > From: Jens Alfke <j...@mooseyard.com> > Subject: Re: NSXML and invalid UTF8 characters > To: "Keith Blount" <keithblo...@yahoo.com> > Cc: cocoa-dev@lists.apple.com > Date: Thursday, January 28, 2010, 11:40 PM > > On Jan 28, 2010, at 3:16 PM, Keith Blount wrote: > > > So, my question is, what is the best way for me to > filter out these invalid characters from my NSString before > I pass it into NSXMLElement's -initWithName:stringValue: or > similar methods, to avoid creating XML documents that won't > open? > > > Make an NSCharacterSet containing the 'bad' characters. > Make a mutable copy of the string. > Use -[NSString rangeOfCharactersFromSet:options:range:] to > iterate through the string finding the 'bad' characters. > Delete each bad character from the mutable string as you > find it. > > If there are only a handful of bad characters, it might be > more straightforward to use NSMutableString's > replaceOccurrencesOfString:withString:options:] method > instead to delete them one at a time. > > —Jens _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com