Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. Manipulating Strings > Converting String Encodings

Converting String Encodings

From: encodings.m

 5 NSString *str =
 6   [NSString stringWithUTF8String:
 7   "some text in a C string"];
 8 const char *utf16 =
 9   [str cStringUsingEncoding:
          NSUTF16StringEncoding];
10 const char *utf32 =
11   [str cStringUsingEncoding:
          NSUTF32StringEncoding];
12 const char *macRoman =
13   [str cStringUsingEncoding:
          NSMacOSRomanStringEncoding];

In OpenStep, two of the most common methods on NSString were -cString and +stringWithCString:. These converted between a C string and an Objective-C string. The problem with these methods was that C strings are not encoding aware.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint