Re: How to detect curly quotes
Re: How to detect curly quotes
- Subject: Re: How to detect curly quotes
- From: Greg Guerin <email@hidden>
- Date: Tue, 31 Mar 2009 16:19:46 -0700
Steve Cronin wrote:
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?
Use one of the non-deprecated stringWithContentsOfFile methods where
you either specify which text-encoding to use, or you get back the
automagically chosen encoding that was used.
If you have some idea of what the file's actual text-encoding is, use
the message that specifies an encoding. If you have no idea, then
use the message that returns the encoding to you.
If you have no idea what the text-encoding is and you may need to try
several until something works properly, then get the file as an
NSData and examine its bytes directly to help interpret what the text-
encoding could be. Once you have a reasonable text-encoding
decision, convert the NSData to NSString.
If this doesn't seem simple enough, it may be impossible to be both
simple and accurate about the actual text-encoding. You may have to
choose between simplicity and accuracy.
-- GG
_______________________________________________
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