Re: stringWithContentsOfURL: usedEncoding: error:
Re: stringWithContentsOfURL: usedEncoding: error:
- Subject: Re: stringWithContentsOfURL: usedEncoding: error:
- From: Greg Stark <email@hidden>
- Date: Mon, 5 Jun 2006 22:03:08 -0600
Supposedly the usedEncoding version of the method tries to determine
the encoding for you (at least according to the Strings Programming
Guide for Cocoa). Apple's suggestion for reading data with unknown
encoding is to try this method first. Also, I'd rather not specify
the encoding if I don't have to because it will give me a little more
flexibility later. I'm just not having much luck with it and am
beginning to think it is broken.
-Greg
On Jun 5, 2006, at 9:47 PM, Adam Leonard wrote:
I think you are a bit confused (or maybe I am). The usingEncoding
parameter does not tell you what encoding it used when reading it;
you must specify what encoding it should use. For a list of
encodings, see: <http://developer.apple.com/documentation/Cocoa/
Reference/Foundation/Classes/NSString_Class/Reference/
Reference.html#//apple_ref/doc/uid/20000154-35474>
I don't know what kind of files you are reading, but it is
*usually* safe to use NSUTF8StringEncoding
So I believe the correct code would be:
NSError *error;
NSString *test = [NSString stringWithContentsOfURL:[URLsToOpen
objectAtIndex:0]
usedEncoding:NSUTF8StringEncoding
error:&error];
Adam
On Jun 5, 2006, at 8:15 PM, Greg Stark wrote:
I caught the error after I posted to the list (I copied the
example from an outdated version of my source and have corrected
it below). With the correction, I get the same error: The file
could not be opened using the specified text encoding.
-Greg
On Jun 5, 2006, at 8:30 PM, Andy Lee wrote:
On Jun 5, 2006, at 10:11 PM, Greg Stark wrote:
NSStringEncoding enc;
NSError *error;
NSString *test = [NSString stringWithContentsOfURL:[URLsToOpen
objectAtIndex:0]
usedEncoding:&enc
error:&error];
NSStringEncoding isn't an object, it's just a typedef for
unsigned. Change
NSStringEncoding *enc;
to
NSStringEncoding enc;
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40bsllc.us
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden