iOS country code及国际区号

本文介绍了一种通过代码实现的国家国际区号获取方法,使用一个预定义的字符串存储了全球多个国家的区号信息,并通过字典进行快速查找。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        /// <summary>
        /// 获取国家国际区号
        /// </summary>
        /// <param name="countryCode"></param>
        /// <returns></returns>
        public static string GetCountryNationCode(string countryCode)
        {
            var nationCodeString = "AD,376,AE,971,AF,93,AG,1268,AI,1264,AL,355,AM,374,AO,244,AR,54,AT,43,AU,61,AZ,994,BB,1246,BD,880,BE,32,BF,226,BG,359,BH,973,BI,257,BJ,229,BL,970,BM,1441,BN,673,BO,591,BR,55,BS,1242,BW,267,BY,375,BZ,501,CA,1,CF,236,CG,242,CH,41,CK,682,CL,56,CM,237,CN,86,CO,57,CR,506,CS,420,CU,53,CY,357,CZ,420,DE,49,DJ,253,DK,45,DO,1890,DZ,213,EC,593,EE,372,EG,20,ES,34,ET,251,FI,358,FJ,679,FR,33,GA,241,GB,44,GD,1809,GE,995,GF,594,GH,233,GI,350,GM,220,GN,224,GR,30,GT,502,GU,1671,GY,592,HK,852,HN,504,HT,509,HU,36,ID,62,IE,353,IL,972,IN,91,IQ,964,IR,98,IS,354,IT,39,JM,1876,JO,962,JP,81,KE,254,KG,331,KH,855,KP,850,KR,82,KT,225,KW,965,KZ,327,LA,856,LB,961,LC,1758,LI,423,LK,94,LR,231,LS,266,LT,370,LU,352,LV,371,LY,218,MA,212,MC,377,MD,373,MG,261,ML,223,MM,95,MN,976,MO,853,MS,1664,MT,356,MU,230,MV,960,MW,265,MX,52,MY,60,MZ,258,NA,264,NE,977,NG,234,NI,505,NL,31,NO,47,NP,977,NR,674,NZ,64,OM,968,PA,507,PE,51,PF,689,PG,675,PH,63,PK,92,PL,48,PR,1787,PT,351,PY,595,QA,974,RO,40,RU,7,SA,966,SB,677,SC,248,SD,249,SE,46,SG,65,SI,386,SK,421,SL,232,SM,378,SN,221,SO,252,SR,597,ST,239,SV,503,SY,963,SZ,268,TD,235,TG,228,TH,66,TJ,992,TM,993,TN,216,TO,676,TR,90,TT,1809,TW,886,TZ,255,UA,380,UG,256,US,1,UY,598,UZ,233,VC,1784,VE,58,VN,84,YE,967,YU,381,ZA,27,ZM,260,ZR,243,ZW,263";
            var nationCodeArray = nationCodeString.Split(',');
            Dictionary<string, string> nationCodekeyValuePairs = new Dictionary<string, string>();
            for (int i = 0; i < nationCodeArray.Count(); i+=2)
            {
                nationCodekeyValuePairs.Add(nationCodeArray[i], nationCodeArray[i + 1]);
            }
            string nationCode = string.Empty;
            nationCodekeyValuePairs.TryGetValue(countryCode.ToUpper(), out nationCode);      
            return nationCode;
        }

下面这几个有需要自己查证下缩写加上

阿森松 Ascension 247
开曼群岛 Cayman Is. 1345
科特迪瓦 Ivory Coast 225
马里亚那群岛 Mariana Is 1670
马提尼克 Martinique 596
荷属安的列斯 Netheriands Antilles 599
留尼旺 Reunion 262
东萨摩亚(美) Samoa Eastern 684
西萨摩亚 San Marino 685

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值