• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSString initWithData: NSUTF8StringEncoding - returns 'nil'
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString initWithData: NSUTF8StringEncoding - returns 'nil'


  • Subject: Re: NSString initWithData: NSUTF8StringEncoding - returns 'nil'
  • From: The Karl Adam <email@hidden>
  • Date: Fri, 3 Dec 2004 13:13:06 -0500

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@hidden> 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@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

References: 
 >NSString initWithData: NSUTF8StringEncoding - returns 'nil' (From: Lance Drake <email@hidden>)
 >Re: NSString initWithData: NSUTF8StringEncoding - returns 'nil' (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: NSString initWithData: NSUTF8StringEncoding - returns 'nil'
  • Next by Date: Re: Different versions of framework?
  • Previous by thread: Re: NSString initWithData: NSUTF8StringEncoding - returns 'nil'
  • Next by thread: Re: Nib files and outlets
  • Index(es):
    • Date
    • Thread