Re: How to detect curly quotes
Re: How to detect curly quotes
- Subject: Re: How to detect curly quotes
- From: John Engelhart <email@hidden>
- Date: Tue, 31 Mar 2009 19:55:47 -0400
On Tue, Mar 31, 2009 at 6:21 PM, Steve Cronin <email@hidden> wrote:
> Folks;
>
> I'm reading input from a text file (stringWithContentsOfFile) I have no
> control over.
> Testing is going well until a I encounter a phrase is wrapped in curly
> quotes.
> (Note phrases wrapped in straight quotes are fine)
>
> Without trying to digest the entirety of the Mac OS Text Encoding system,
> can someone suggest a simple way to detect these characters?
>
You can use regular expressions. RegexKitLite @
http://regexkit.sourceforge.net/RegexKitLite/ which you can download at
http://downloads.sourceforge.net/regexkit/RegexKitLite-2.2.tar.bz2
For example, you can be extremely lazy and do something along the lines of:
NSStringEncoding fileEncoding;
NSString *fileString = [[NSString stringWithContentsOfFile:@"file.txt"
usedEncoding:&fileEncoding error:NULL] stringByReplacingOccurrencesOfRegex:@
"[\u201c\u201d]" withString:@"\""];
And violla! This will turn “ (\u201c) and ” (\u201d) in 'file.txt' into a
plain " (ascii 0x22), the result of which is fileString.
There's other methods available as well if you just need to find the
locations of the curly quotes and what not. Well documented, and the
documentation is available in .docset format so it's integrated and
available inside Xcode, just like all the other documentation.
_______________________________________________
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