Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Codice valuta a 3 cifre in simbolo valuta

Anche se un po' brutale e non particolarmente elegante, potresti farlo in questo modo:

public bool TryGetCurrencySymbol(string ISOCurrencySymbol, out string symbol)
{
    symbol = CultureInfo
        .GetCultures(CultureTypes.AllCultures)
        .Where(c => !c.IsNeutralCulture)
        .Select(culture => {
            try{
                return new RegionInfo(culture.Name);
            }
            catch
            {
                return null;
            }
        })
        .Where(ri => ri!=null && ri.ISOCurrencySymbol == ISOCurrencySymbol)
        .Select(ri => ri.CurrencySymbol)
        .FirstOrDefault();
    return symbol != null;
}

e usalo come segue:

string currSymbol;
if(TryGetCurrencySymbol("GBP",out currSymbol))
{
    Console.WriteLine("symbol is {0}", currSymbol);
}

Se prevedi di martellare questo metodo, forse è meglio creare una cache in anticipo:

public static class CurrencyTools
{
    private static IDictionary<string,string> map;
    static CurrencyTools()
    {
        map = CultureInfo
            .GetCultures(CultureTypes.AllCultures)
            .Where(c => !c.IsNeutralCulture)
            .Select(culture => {
                try{
                    return new RegionInfo(culture.Name);
                }
                catch
                {
                    return null;
                }
            })
            .Where(ri => ri!=null)
            .GroupBy(ri => ri.ISOCurrencySymbol)
            .ToDictionary(x => x.Key, x => x.First().CurrencySymbol);
    }
    public static bool TryGetCurrencySymbol(
                          string ISOCurrencySymbol, 
                          out string symbol)
    {
        return map.TryGetValue(ISOCurrencySymbol,out symbol);
    }
}

Nel momento in cui scrivo, sulla mia macchina ecc. ecc. la mappa contiene le seguenti mappature:

AED  د.إ.‏
AFN  ؋
ALL  Lekë
AMD  ֏
ANG  NAf.
AOA  Kz
ARS  $
AUD  $
AWG  Afl.
AZN  ₼
BAM  КМ
BBD  $
BDT  ৳
BGN  лв.
BHD  د.ب.‏
BIF  FBu
BMD  $
BND  $
BOB  Bs
BRL  R$
BSD  $
BTN  Nu.
BWP  P
BYN  Br
BZD  $
CAD  $
CDF  FC
CHF  CHF
CLP  $
CNY  ¥
COP  $
CRC  ₡
CUP  $
CVE  ​
CZK  Kč
DJF  Fdj
DKK  kr.
DOP  $
DZD  د.ج.‏
EGP  ج.م.‏
ERN  Nfk
ETB  Br
EUR  €
FJD  $
FKP  £
GBP  £
GEL  ₾
GHS  GH₵
GIP  £
GMD  D
GNF  FG
GTQ  Q
GYD  $
HKD  $
HNL  L
HRK  kn
HTG  G
HUF  Ft
IDR  Rp
ILS  ₪
INR  ₹
IQD  د.ع.‏
IRR  ريال
ISK  kr
JMD  $
JOD  د.ا.‏
JPY  ¥
KES  Ksh
KGS  сом
KHR  ៛
KMF  CF
KPW  ₩
KRW  ₩
KWD  د.ك.‏
KYD  $
KZT  ₸
LAK  ₭
LBP  ل.ل.‏
LKR  රු.
LRD  $
LYD  د.ل.‏
MAD  د.م.‏
MDL  L
MGA  Ar
MKD  ден
MMK  K
MNT  ₮
MOP  MOP$
MRU  MRU
MUR  Rs
MVR  ރ.
MWK  MK
MXN  $
MYR  RM
MZN  MTn
NAD  $
NGN  ₦
NIO  C$
NOK  kr
NPR  रु
NZD  $
OMR  ر.ع.‏
PAB  B/.
PEN  S/
PGK  K
PHP  ₱
PKR  Rs
PLN  zł
PYG  ₲
QAR  ر.ق.‏
RON  lei
RSD  дин.
RUB  ₽
RWF  RF
SAR  ر.س.‏
SBD  $
SCR  SR
SDG  ج.س.
SEK  kr
SGD  $
SHP  £
SLL  Le
SOS  S
SRD  $
SSP  £
STN  Db
SYP  ل.س.‏
SZL  E
THB  ฿
TJS  смн
TMT  m.
TND  د.ت.‏
TOP  T$
TRY  ₺
TTD  $
TWD  NT$
TZS  TSh
UAH  ₴
UGX  USh
USD  $
UYU  $
UZS  сўм
VES  Bs.S
VND  ₫
VUV  VT
WST  WS$
XAF  FCFA
XCD  EC$
XDR  XDR
XOF  CFA
XPF  FCFP
YER  ر.ي.‏
ZAR  R
ZMW  K