Skip navigation.
 
mlRe: NSString initWithData: NSUTF8StringEncoding - returns 'nil'
FROM : The Karl Adam
DATE : Fri Dec 03 19:13:06 2004

Also UTF-8 assumes that the input data is a normal UTF-8 string or a
null terminated unichar *, though UTF-8 encompasses all of ASCII, the
char * may not line up correctly for certain characters and by default
the init methods do nonLossy encoding so if an unknown/unexpected
character is encountered, nil is returned.

-Karl


On Fri, 3 Dec 2004 10:04:45 -0800, Douglas Davidson <<email_removed>> wrote:
>
>
>
> On Dec 3, 2004, at 9:52 AM, Lance Drake wrote:
>
> > I'm reading an RTF file which is contained in a binary file.  I need
> > to create an RTF file on the HD - but am having a problem when I try
> > to move the data thru the system.
> >
> > The following line of code works 'sometimes' with the same data:
> > NSString* theString = [[NSString alloc] initWithData:strData
> > encoding:NSUTF8StringEncoding];
> >
> > This line of code always works - with the very same data input:
> > NSString* theString = [[NSString alloc] initWithData:strData
> > encoding:NSASCIIStringEncoding];
> >
> > The data is an RTF file which currently does not contain any special
> > UTF8 characters - but could.
>
> The contents of an RTF file may look like a string, but they're not;
> they should be treated as data.  Leave it as an NSData and read and
> write it using NSData methods.
>
> Douglas Davidson
>
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/karl.<email_removed>
>
> This email sent to karl.<email_removed>
>

Related mailsAuthorDate
mlNSString initWithData: NSUTF8StringEncoding - returns 'nil' Lance Drake Dec 3, 18:52
mlRe: NSString initWithData: NSUTF8StringEncoding - returns 'nil' Douglas Davidson Dec 3, 19:04
mlRe: NSString initWithData: NSUTF8StringEncoding - returns 'nil' Lance Drake Dec 3, 19:12
mlRe: NSString initWithData: NSUTF8StringEncoding - returns 'nil' The Karl Adam Dec 3, 19:13