Re: NSXML and invalid UTF8 characters
Re: NSXML and invalid UTF8 characters
- Subject: Re: NSXML and invalid UTF8 characters
- From: Keith Blount <email@hidden>
- Date: Thu, 28 Jan 2010 15:47:12 -0800 (PST)
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 <email@hidden> wrote:
> From: Jens Alfke <email@hidden>
> Subject: Re: NSXML and invalid UTF8 characters
> To: "Keith Blount" <email@hidden>
> Cc: email@hidden
> 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 (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