在NSArray中生成货币符号

时间:2014-04-08 10:10:21

标签: ios objective-c nsarray

我想在数组中生成货币符号。如果我直接采取它得到错误非ascii代码不支持。这些是符号

United States ($ ) 
 United Kingdom (£ ) 
 Euro Member (€ ) 
 Australia ($ ) 
 Albania (Lek ) 
 Afghanistan (؋ ) 
 Argentina ($ ) 
 Aruba (ƒ ) 
 Azerbaijan (ман ) 
 Bahamas ($ ) 
 Barbados ($ ) 
 Belarus (p. ) 
 Belize (BZ$ ) 
 Bermuda ($ ) 
 Bolivia ($b ) 
 Bosnia and Herzegovina (KM ) 
 Botswana (P ) 
 Bulgaria (лв ) 
 Brazil (R$ ) 
 Brunei ($ ) 
 Canada ($ ) 
 Cayman ($ ) 
 Chile ($ ) 
 China (¥ ) 
 Colombia ($ ) 
 Costa Rica (₡ ) 
 Croatia (kn ) 
 Cuba (₱ ) 
 Czech Republic (Kč ) 
 Denmark (kr ) 
 Dominican Republic (RD$ ) 
 East Caribbean ($ ) 
 Egypt (£ ) 
 El Salvador ($ ) 
 Estonia (kr ) 
 Falkland Islands (£ ) 
 Fiji ($ ) 
 Ghana (¢ ) 
 Gibraltar (£ ) 
 Guatemala (Q ) 
 Guernsey (£ ) 
 Guyana ($ ) 
 Honduras (L ) 
 Hong Kong ($ ) 
 Hungary (Ft ) 
 Iceland (kr ) 
 India (₹ ) 
 Indonesia (Rp ) 
 Iran (ریال)  
 Isle of Man (£ ) 
 Israel (₪ ) 
 Jamaica (J$ ) 
 Japan (¥ ) 
 Jersey (£ ) 
 Kazakhstan (лв ) 
 NorthKorea (₩ ) 
 South Korea (₩ ) 
 Kyrgyzstan (лв ) 
 Laos (₭ ) 
 Latvia (Ls ) 
 Lebanon (£ ) 
 Liberia ($ ) 
 Lithuania (Lt ) 
 Macedonia (ден ) 
 Malaysia (RM ) 
 Mauritius (Rs ) 
 Mexico ($ ) 
 Mongolia (₮ ) 
 Mozambique (MT ) 
 Namibia ($ ) 
 Nepal (Rs ) 
 Netherlands (ƒ ) 
 New Zealand ($ ) 
 Nicaragua (C$ ) 
 Nigeria (₦ ) 
 Norway (kr ) 
 Oman (﷼) 
 Pakistan (Rs ) 
 Panama (B/. ) 
 Paraguay (Gs ) 
 Peru (S/. ) 
 Philippines (₱ ) 
 Poland (zł ) 
 Qatar (﷼) ‫
 Romania (lei ) 
 Russia (руб ) 
 Saint Helena (£ ) 
 Saudi Arabia (﷼) 
 Serbia (Дин. ) 
 Seychelles (Rs ) 
 Singapore ($ ) 
 Solomon Islands ($ ) 
 Somalia (S ) 
 South Africa (S ) 
 Sri Lanka (Rs ) 
 Sweden (kr ) 
 Switzerland (CHF ) 
 Suriname ($ ) 
 Syria (£ ) 
 Taiwan (NT$ ) 
 Thailand (฿ ) 
 Trinidad and Tobago (TT$ ) 
 Turkey (₤ ) 
 Tuvalu ($ ) 
 Ukraine (₴ ) 
 Uruguay ($U ) 
 Uzbekistan (лв ) 
 Venezuela (Bs ) 
 Viet Nam (₫ ) 
 Yemen (﷼) 
 Zimbabwe (Z$ )

如何将这些符号带入数组?

3 个答案:

答案 0 :(得分:2)

NSArray * ids = [NSLocale availableLocaleIdentifiers];
NSMutableArray * symbols = [NSMutableArray array];

for (NSString * localeIdentifier in ids) {
    NSLocale * locale = [NSLocale localeWithLocaleIdentifier:localeIdentifier];
    NSString * symbol = [locale objectForKey:NSLocaleCurrencySymbol];

    if (symbol)
        [symbols addObject:symbol];
}

代码使用NSLocale循环遍历可用的系统区域设置标识符,并获取每种货币的符号(NSLocaleCurrencySymbol)。

答案 1 :(得分:0)

获取符号的unicode,将其转换为NSString,然后将其添加到数组中。 例如,对于$ symbol:

char cString[] = "\u0024";
NSData *data = [NSData dataWithBytes:cString length:strlen(cString)];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"result string: %@", string);
[arr addObject:string];

答案 2 :(得分:-1)

非常简单的尝试这个......

NSArray* currency = [NSLocale availableLocaleIdentifiers];

for (int i = 0; i < [currency count]; i++) {
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:currency[i]];
    NSString *currencyCode = [locale objectForKey:NSLocaleCurrencyCode];
    NSString *currencySymbol = [locale objectForKey:NSLocaleCurrencySymbol];
    NSLog( @"Code: %@ Symbol %@", currencyCode,currencySymbol );
}