Tuesday, May 21, 2013

NSString NSNEXTSTEPStringEncoding example ios


String Encodings - NSNEXTSTEPStringEncoding

The following constants are provided by NSString as possible string encodings.
enum {
   NSASCIIStringEncoding = 1,
   NSNEXTSTEPStringEncoding = 2,
   NSJapaneseEUCStringEncoding = 3,
   NSUTF8StringEncoding = 4,
   NSISOLatin1StringEncoding = 5,
   NSSymbolStringEncoding = 6,
   NSNonLossyASCIIStringEncoding = 7,
   NSShiftJISStringEncoding = 8,
   NSISOLatin2StringEncoding = 9,
   NSUnicodeStringEncoding = 10,
   NSWindowsCP1251StringEncoding = 11,
   NSWindowsCP1252StringEncoding = 12,
   NSWindowsCP1253StringEncoding = 13,
   NSWindowsCP1254StringEncoding = 14,
   NSWindowsCP1250StringEncoding = 15,
   NSISO2022JPStringEncoding = 21,
   NSMacOSRomanStringEncoding = 30,
   NSUTF16StringEncoding = NSUnicodeStringEncoding,
   NSUTF16BigEndianStringEncoding = 0x90000100,
   NSUTF16LittleEndianStringEncoding = 0x94000100,
   NSUTF32StringEncoding = 0x8c000100,
   NSUTF32BigEndianStringEncoding = 0x98000100,
   NSUTF32LittleEndianStringEncoding = 0x9c000100,
   NSProprietaryStringEncoding = 65536
};
Constants
NSNEXTSTEPStringEncoding
8-bit ASCII encoding with NEXTSTEP extensions.
Discussion of [NSString NSNEXTSTEPStringEncoding]
These values represent the various character encodings supported by the NSStringclasses. This is an incomplete list. Additional encodings are defined in String Programming Guide for Core Foundation (see CFStringEncodingExt.h); these encodings can be used with NSString by first passing the Core Foundation encoding to the CFStringConvertEncodingToNSStringEncoding function.
Example of [NSString NSNEXTSTEPStringEncoding]
void MyLog(NSString *format, ...) {
    va_list args;
    va_start(args, format);
    NSString *formattedString = [[NSString alloc] initWithFormat: format
                                                  arguments: args];
    va_end(args);
    [[NSFileHandle fileHandleWithStandardOutput]
        writeData: [formattedString dataUsingEncoding: NSNEXTSTEPStringEncoding];
    [formattedString release];
}
Example of [NSString NSNEXTSTEPStringEncoding]
void MyLog(NSString *format, ...)
{
    va_list args;
    va_start(args, format);
    NSString *formattedString = [[NSString alloc] initWithFormat:format arguments: args];
    va_end(args);
    [[NSFileHandle fileHandleWithStandardOutput] writeData:[formattedString dataUsingEncoding: NSNEXTSTEPStringEncoding]];
    [formattedString release];
}
Example of [NSString NSNEXTSTEPStringEncoding]
CGGlyph* Glyphs = malloc(sizeof(CGGlyph) * [textToDraw length]);
 char* Chars = malloc(sizeof(char) * ([textToDraw length] + 1));
 [textToDraw getCString:Chars maxLength: ([textToDraw length] + 1) encoding: NSNEXTSTEPStringEncoding];

 for(int CurrentChar = 0; CurrentChar < [textToDraw length]; ++CurrentChar)
 {
  Glyphs[CurrentChar] = Chars[CurrentChar]- 29;
 }
 CGContextShowGlyphs(UIGraphicsGetCurrentContext(), Glyphs, [textToDraw length])