NSString对应的编码格式,查询NSStringEncoding


NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding (kCFStringEncodingGB_18030_2000);    //GB2312,GBK


创建一个mac os的工程,加入代码:

const NSStringEncoding *encodings = [NSString availableStringEncodings];
    
    NSMutableString *str = [[NSMutableString alloc] init];
    
    NSStringEncoding encoding;
    
    while ((encoding = *encodings++) != 0)
    {
        
        [str appendFormat: @"%@ === %li\n", [NSString localizedNameOfStringEncoding:encoding], encoding];
    }
    NSLog(@"%@",str);

得到:

Western (Mac OS Roman) === 30

Japanese (Mac OS) === 2147483649

Traditional Chinese (Mac OS) === 2147483650

Korean (Mac OS) === 2147483651

Arabic (Mac OS) === 2147483652

Hebrew (Mac OS) === 2147483653

Greek (Mac OS) === 2147483654

Cyrillic (Mac OS) === 2147483655

Devanagari (Mac OS) === 2147483657

Gurmukhi (Mac OS) === 2147483658

Gujarati (Mac OS) === 2147483659

Thai (Mac OS) === 2147483669

Simplified Chinese (Mac OS) === 2147483673

Tibetan (Mac OS) === 2147483674

Central European (Mac OS) === 2147483677

Symbol (Mac OS) === 6

Dingbats (Mac OS) === 2147483682

Turkish (Mac OS) === 2147483683

Croatian (Mac OS) === 2147483684

Icelandic (Mac OS) === 2147483685

Romanian (Mac OS) === 2147483686

Celtic (Mac OS) === 2147483687

Gaelic (Mac OS) === 2147483688

Keyboard Symbols (Mac OS) === 2147483689

Farsi (Mac OS) === 2147483788

Cyrillic (Mac OS Ukrainian) === 2147483800

Inuit (Mac OS) === 2147483884

Unicode (UTF-16) === 10

Unicode (UTF-7) === 2214592768

Unicode (UTF-8) === 4

Unicode (UTF-32) === 2348810496

Unicode (UTF-16BE) === 2415919360

Unicode (UTF-16LE) === 2483028224

Unicode (UTF-32BE) === 2550137088

Unicode (UTF-32LE) === 2617245952

Western (ISO Latin 1) === 5

Central European (ISO Latin 2) === 9

Western (ISO Latin 3) === 2147484163

Central European (ISO Latin 4) === 2147484164

Cyrillic (ISO 8859-5) === 2147484165

Arabic (ISO 8859-6) === 2147484166

Greek (ISO 8859-7) === 2147484167

Hebrew (ISO 8859-8) === 2147484168

Turkish (ISO Latin 5) === 2147484169

Nordic (ISO Latin 6) === 2147484170

Thai (ISO 8859-11) === 2147484171

Baltic (ISO Latin 7) === 2147484173

Celtic (ISO Latin 8) === 2147484174

Western (ISO Latin 9) === 2147484175

Romanian (ISO Latin 10) === 2147484176

Latin-US (DOS) === 2147484672

Greek (DOS) === 2147484677

Baltic (DOS) === 2147484678

Western (DOS Latin 1) === 2147484688

Greek (DOS Greek 1) === 2147484689

Central European (DOS Latin 2) === 2147484690

Cyrillic (DOS) === 2147484691

Turkish (DOS) === 2147484692

Portuguese (DOS) === 2147484693

Icelandic (DOS) === 2147484694

Hebrew (DOS) === 2147484695

Canadian French (DOS) === 2147484696

Arabic (DOS) === 2147484697

Nordic (DOS) === 2147484698

Russian (DOS) === 2147484699

Greek (DOS Greek 2) === 2147484700

Thai (Windows, DOS) === 2147484701

Japanese (Windows, DOS) === 8

Simplified Chinese (Windows, DOS) === 2147484705

Korean (Windows, DOS) === 2147484706

Traditional Chinese (Windows, DOS) === 2147484707

Western (Windows Latin 1) === 12

Central European (Windows Latin 2) === 15

Cyrillic (Windows) === 11

Greek (Windows) === 13

Turkish (Windows Latin 5) === 14

Hebrew (Windows) === 2147484933

Arabic (Windows) === 2147484934

Baltic (Windows) === 2147484935

Vietnamese (Windows) === 2147484936

Western (ASCII) === 1

Japanese (Shift JIS X0213) === 2147485224

Chinese (GBK) === 2147485233

Chinese (GB 18030) === 2147485234

Japanese (ISO 2022-JP) === 21

Japanese (ISO 2022-JP-2) === 2147485729

Japanese (ISO 2022-JP-1) === 2147485730

Chinese (ISO 2022-CN) === 2147485744

Korean (ISO 2022-KR) === 2147485760

Japanese (EUC) === 3

Simplified Chinese (GB 2312) === 2147486000

Traditional Chinese (EUC) === 2147486001

Korean (EUC) === 2147486016

Japanese (Shift JIS) === 2147486209

Cyrillic (KOI8-R) === 2147486210

Traditional Chinese (Big 5) === 2147486211

Western (Mac Mail) === 2147486212

Simplified Chinese (HZ GB 2312) === 2147486213

Traditional Chinese (Big 5 HKSCS) === 2147486214

Ukrainian (KOI8-U) === 2147486216

Traditional Chinese (Big 5-E) === 2147486217

Western (NextStep) === 2

Non-lossy ASCII === 7

Western (EBCDIC Latin Core) === 2147486721

Western (EBCDIC Latin 1) === 2147486722


得到这么多神奇的数字,这些神奇的数字就是对应的编码格式。


---------------------------分割线-----------------------


得到的是有符号的long类型:

const NSStringEncoding *encodings = [NSString availableStringEncodings];
    NSMutableString *str = [[NSMutableString alloc] init];
    NSStringEncoding encoding;
    while ((encoding = *encodings++) != 0)
    {
        [str appendFormat: @"%@ === %i\n", [NSString localizedNameOfStringEncoding:encoding], encoding];
    }
    NSLog(@"%@",str);

下面是mac os的格式代码:
Western (Mac OS Roman) === 30
Japanese (Mac OS) === -2147483647
Traditional Chinese (Mac OS) === -2147483646
Korean (Mac OS) === -2147483645
Arabic (Mac OS) === -2147483644
Hebrew (Mac OS) === -2147483643
Greek (Mac OS) === -2147483642
Cyrillic (Mac OS) === -2147483641
Devanagari (Mac OS) === -2147483639
Gurmukhi (Mac OS) === -2147483638
Gujarati (Mac OS) === -2147483637
Thai (Mac OS) === -2147483627
Simplified Chinese (Mac OS) === -2147483623
Tibetan (Mac OS) === -2147483622
Central European (Mac OS) === -2147483619
Symbol (Mac OS) === 6
Dingbats (Mac OS) === -2147483614
Turkish (Mac OS) === -2147483613
Croatian (Mac OS) === -2147483612
Icelandic (Mac OS) === -2147483611
Romanian (Mac OS) === -2147483610
Celtic (Mac OS) === -2147483609
Gaelic (Mac OS) === -2147483608
Keyboard Symbols (Mac OS) === -2147483607
Farsi (Mac OS) === -2147483508
Cyrillic (Mac OS Ukrainian) === -2147483496
Inuit (Mac OS) === -2147483412
Unicode (UTF-16) === 10
Unicode (UTF-7) === -2080374528
Unicode (UTF-8) === 4
Unicode (UTF-32) === -1946156800
Unicode (UTF-16BE) === -1879047936
Unicode (UTF-16LE) === -1811939072
Unicode (UTF-32BE) === -1744830208
Unicode (UTF-32LE) === -1677721344
Western (ISO Latin 1) === 5
Central European (ISO Latin 2) === 9
Western (ISO Latin 3) === -2147483133
Central European (ISO Latin 4) === -2147483132
Cyrillic (ISO 8859-5) === -2147483131
Arabic (ISO 8859-6) === -2147483130
Greek (ISO 8859-7) === -2147483129
Hebrew (ISO 8859-8) === -2147483128
Turkish (ISO Latin 5) === -2147483127
Nordic (ISO Latin 6) === -2147483126
Thai (ISO 8859-11) === -2147483125
Baltic (ISO Latin 7) === -2147483123
Celtic (ISO Latin 8) === -2147483122
Western (ISO Latin 9) === -2147483121
Romanian (ISO Latin 10) === -2147483120
Latin-US (DOS) === -2147482624
Greek (DOS) === -2147482619
Baltic (DOS) === -2147482618
Western (DOS Latin 1) === -2147482608
Greek (DOS Greek 1) === -2147482607
Central European (DOS Latin 2) === -2147482606
Cyrillic (DOS) === -2147482605
Turkish (DOS) === -2147482604
Portuguese (DOS) === -2147482603
Icelandic (DOS) === -2147482602
Hebrew (DOS) === -2147482601
Canadian French (DOS) === -2147482600
Arabic (DOS) === -2147482599
Nordic (DOS) === -2147482598
Russian (DOS) === -2147482597
Greek (DOS Greek 2) === -2147482596
Thai (Windows, DOS) === -2147482595
Japanese (Windows, DOS) === 8
Simplified Chinese (Windows, DOS) === -2147482591
Korean (Windows, DOS) === -2147482590
Traditional Chinese (Windows, DOS) === -2147482589
Western (Windows Latin 1) === 12
Central European (Windows Latin 2) === 15
Cyrillic (Windows) === 11
Greek (Windows) === 13
Turkish (Windows Latin 5) === 14
Hebrew (Windows) === -2147482363
Arabic (Windows) === -2147482362
Baltic (Windows) === -2147482361
Vietnamese (Windows) === -2147482360
Western (ASCII) === 1
Japanese (Shift JIS X0213) === -2147482072
Chinese (GBK) === -2147482063
Chinese (GB 18030) === -2147482062
Japanese (ISO 2022-JP) === 21
Japanese (ISO 2022-JP-2) === -2147481567
Japanese (ISO 2022-JP-1) === -2147481566
Chinese (ISO 2022-CN) === -2147481552
Korean (ISO 2022-KR) === -2147481536
Japanese (EUC) === 3
Simplified Chinese (GB 2312) === -2147481296
Traditional Chinese (EUC) === -2147481295
Korean (EUC) === -2147481280
Japanese (Shift JIS) === -2147481087
Cyrillic (KOI8-R) === -2147481086
Traditional Chinese (Big 5) === -2147481085
Western (Mac Mail) === -2147481084
Simplified Chinese (HZ GB 2312) === -2147481083
Traditional Chinese (Big 5 HKSCS) === -2147481082
Ukrainian (KOI8-U) === -2147481080
Traditional Chinese (Big 5-E) === -2147481079
Western (NextStep) === 2
Non-lossy ASCII === 7
Western (EBCDIC Latin Core) === -2147480575
Western (EBCDIC Latin 1) === -2147480574



你可能感兴趣的:(ios)