Re: NSXML and invalid UTF8 characters
Re: NSXML and invalid UTF8 characters
- Subject: Re: NSXML and invalid UTF8 characters
- From: Jens Alfke <email@hidden>
- Date: Thu, 28 Jan 2010 15:40:36 -0800
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 (email@hidden)
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:
This email sent to email@hidden