Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:



Preformatovani telefonniho cisla

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: Preformatovani telefonniho cisla

Autor: TC ♂

13:56:42 02.01.2013

static string Hamoun(string s)
{
return Regex.Replace(string.Join(" ",Regex.Split(s, @"(\d{3})")),@"[\s]+"," ");
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

13:20:22 02.01.2013

hamon napsal/a

Dost, dost, dik, uz jsem se v tom ztratil :)


class Program
{
static void Main(string[] args)
{
string[] num = new string[] { "+420 123 456 789", "+352123 456789", "123456789", "12345", "+420123 456789 1234567", "+1123456789" };
foreach (string s in num)
Console.WriteLine(Hamoun(s));
}
static string Hamoun(string s)
{
return Regex.Replace(string.Join(" ",Regex.Split(Regex.Replace(s, @"[^+^0-9]+", ""), @"(\d{3})")),@"[\s]+"," ");
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: hamon ♂

12:16:02 02.01.2013

Dost, dost, dik, uz jsem se v tom ztratil :)

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

11:14:54 02.01.2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace Hamon
{
/// <summary>
/// Kdyz uz, tak poradne a bez bezducheho tlaceni 9 cifer
/// Seznam je usporadan tak, aby eliminoval bordel s +1
/// </summary>
class Program
{
static void Main(string[] args)
{
string[] num = new string[] { "+420 123 456 789", "+352123 456789", "123456789", "12345", "+420123 456789 1234567", "+1123456789" };
foreach (string s in num)
Console.WriteLine(CountryData.Hamoun(s));
}
}
public class CountryData
{
public static string Hamoun(string num)
{
num = Regex.Replace(num, @"[^+^0-9]+", "");
var code = "+420";
foreach (var c in data.Keys)
{
if (num.StartsWith(c))
{
num = num.Replace(c, "");
code = c;
break;
}
}
return data[code].z_fmt(code, num);
}

delegate string Formatter(string code, string number);
string z_country;
string z_abbrev;
int z_popul;
Formatter z_fmt;
CountryData(Formatter fmt, string country, string abbrev, int popul)
{
z_country = country;
z_abbrev = abbrev;
z_fmt = fmt;
z_popul = popul;
}
static string Standard(string code, string number) { return Mask(code, " *** *** ***", number); }
static string Force__9(string code, string number) { return Mask(code, " *** *** ***", Force(number, 9)); }
static string US_Rules(string code, string number) { return Mask(code, "-***-****-***", number); }
static string Mask(string code, string mask, string number)
{
var sb = new StringBuilder(code);
int i = 0;
foreach (var c in mask)
{
if (c == '*')
{
sb.Append(number[i++]);
if (i >= number.Length) break;
}
else sb.Append(c);
}
for (; i < number.Length; i++) sb.Append(number[i]);
return sb.ToString();
}
static string Force(string num, int digits)
{
if (num.Length < digits) return num.PadLeft(digits, '0'); // what a stupidity Hamoun asks for
if (num.Length > digits) return num.Substring(0, digits);
return num;
}
static Dictionary<string, CountryData> data = new Dictionary<string, CountryData>{
{ "+1242", new CountryData(Standard,"Bahamas" ,"BS/BHS" , 309156)},
{ "+1246", new CountryData(Standard,"Barbados" ,"BB/BRB" , 284589)},
{ "+1264", new CountryData(Standard,"Anguilla" ,"AI/AIA" , 14436)},
{ "+1268", new CountryData(Standard,"AntiguaandBarbuda" ,"AG/ATG" , 85632)},
{ "+1284", new CountryData(Standard,"BritishVirginIslands" ,"VG/VGB" , 24491)},
{ "+1340", new CountryData(Standard,"USVirginIslands" ,"VI/VIR" , 109825)},
{ "+1345", new CountryData(Standard,"CaymanIslands" ,"KY/CYM" , 49035)},
{ "+1441", new CountryData(Standard,"Bermuda" ,"BM/BMU" , 67837)},
{ "+1473", new CountryData(Standard,"Grenada" ,"GD/GRD" , 90739)},
{ "+1599", new CountryData(Standard,"SaintMartin" ,"MF/MAF" , 29820)},
{ "+1649", new CountryData(Standard,"TurksandCaicosIslands" ,"TC/TCA" , 22942)},
{ "+1664", new CountryData(Standard,"Montserrat" ,"MS/MSR" , 5097)},
{ "+1670", new CountryData(Standard,"NorthernMarianaIslands" ,"MP/MNP" , 88662)},
{ "+1671", new CountryData(Standard,"Guam" ,"GU/GUM" , 160595)},
{ "+1684", new CountryData(Standard,"AmericanSamoa" ,"AS/ASM" , 65628)},
{ "+1758", new CountryData(Standard,"SaintLucia" ,"LC/LCA" , 160267)},
{ "+1767", new CountryData(Standard,"Dominica" ,"DM/DMA" , 72660)},
{ "+1784", new CountryData(Standard,"SaintVincentandtheGrenadines","VC/VCT" , 104574)},
{ "+1809", new CountryData(Standard,"DominicanRepublic" ,"DO/DOM" , 9650054)},
{ "+1868", new CountryData(Standard,"TrinidadandTobago" ,"TT/TTO" , 1229953)},
{ "+1869", new CountryData(Standard,"SaintKittsandNevis" ,"KN/KNA" , 40131)},
{ "+1876", new CountryData(Standard,"Jamaica" ,"JM/JAM" , 2825928)},
{ "+1c", new CountryData(Standard,"Canada" ,"CA/CAN" , 33487208)},
{ "+1x", new CountryData(Standard,"PuertoRico" ,"PR/PRI" , 3971020)},
{ "+1", new CountryData(US_Rules,"UnitedStates" ,"US/USA" , 307212123)},
{ "+20", new CountryData(Standard,"Egypt" ,"EG/EGY" , 83082869)},
{ "+212", new CountryData(Standard,"Morocco" ,"MA/MAR" , 34859364)},
{ "+213", new CountryData(Standard,"Algeria" ,"DZ/DZA" , 34178188)},
{ "+216", new CountryData(Standard,"Tunisia" ,"TN/TUN" , 10486339)},
{ "+218", new CountryData(Standard,"Libya" ,"LY/LBY" , 6310434)},
{ "+220", new CountryData(Standard,"Gambia" ,"GM/GMB" , 1782893)},
{ "+221", new CountryData(Standard,"Senegal" ,"SN/SEN" , 13711597)},
{ "+222", new CountryData(Standard,"Mauritania" ,"MR/MRT" , 3129486)},
{ "+223", new CountryData(Standard,"Mali" ,"ML/MLI" , 12666987)},
{ "+224", new CountryData(Standard,"Guinea" ,"GN/GIN" , 10057975)},
{ "+225", new CountryData(Standard,"IvoryCoast" ,"CI/CIV" , 20617068)},
{ "+226", new CountryData(Standard,"BurkinaFaso" ,"BF/BFA" , 15746232)},
{ "+227", new CountryData(Standard,"Niger" ,"NE/NER" , 15306252)},
{ "+228", new CountryData(Standard,"Togo" ,"TG/TGO" , 6019877)},
{ "+229", new CountryData(Standard,"Benin" ,"BJ/BEN" , 8791832)},
{ "+230", new CountryData(Standard,"Mauritius" ,"MU/MUS" , 1284264)},
{ "+231", new CountryData(Standard,"Liberia" ,"LR/LBR" , 3441790)},
{ "+232", new CountryData(Standard,"SierraLeone" ,"SL/SLE" , 6440053)},
{ "+233", new CountryData(Standard,"Ghana" ,"GH/GHA" , 23832495)},
{ "+234", new CountryData(Standard,"Nigeria" ,"NG/NGA" , 149229090)},
{ "+235", new CountryData(Standard,"Chad" ,"TD/TCD" , 10329208)},
{ "+236", new CountryData(Standard,"CentralAfricanRepublic" ,"CF/CAF" , 4511488)},
{ "+237", new CountryData(Standard,"Cameroon" ,"CM/CMR" , 18879301)},
{ "+238", new CountryData(Standard,"CapeVerde" ,"CV/CPV" , 429474)},
{ "+239", new CountryData(Standard,"SaoTomeandPrincipe" ,"ST/STP" , 212679)},
{ "+240", new CountryData(Standard,"EquatorialGuinea" ,"GQ/GNQ" , 633441)},
{ "+241", new CountryData(Standard,"Gabon" ,"GA/GAB" , 1514993)},
{ "+242", new CountryData(Standard,"RepublicoftheCongo" ,"CG/COG" , 4012809)},
{ "+243", new CountryData(Standard,"DemocraticRepublicoftheCongo","CD/COD" , 68692542)},
{ "+244", new CountryData(Standard,"Angola" ,"AO/AGO" , 12799293)},
{ "+245", new CountryData(Standard,"Guinea-Bissau" ,"GW/GNB" , 1533964)},
{ "+248", new CountryData(Standard,"Seychelles" ,"SC/SYC" , 87476)},
{ "+249", new CountryData(Standard,"Sudan" ,"SD/SDN" , 41087825)},
{ "+250", new CountryData(Standard,"Rwanda" ,"RW/RWA" , 10473282)},
{ "+251", new CountryData(Standard,"Ethiopia" ,"ET/ETH" , 85237338)},
{ "+252", new CountryData(Standard,"Somalia" ,"SO/SOM" , 9832017)},
{ "+253", new CountryData(Standard,"Djibouti" ,"DJ/DJI" , 516055)},
{ "+254", new CountryData(Standard,"Kenya" ,"KE/KEN" , 39002772)},
{ "+255", new CountryData(Standard,"Tanzania" ,"TZ/TZA" , 41048532)},
{ "+256", new CountryData(Standard,"Uganda" ,"UG/UGA" , 32369558)},
{ "+257", new CountryData(Standard,"Burundi" ,"BI/BDI" , 8988091)},
{ "+258", new CountryData(Standard,"Mozambique" ,"MZ/MOZ" , 21669278)},
{ "+260", new CountryData(Standard,"Zambia" ,"ZM/ZMB" , 11862740)},
{ "+261", new CountryData(Standard,"Madagascar" ,"MG/MDG" , 20653556)},
{ "+262", new CountryData(Standard,"Mayotte" ,"YT/MYT" , 223765)},
{ "+263", new CountryData(Standard,"Zimbabwe" ,"ZW/ZWE" , 11392629)},
{ "+264", new CountryData(Standard,"Namibia" ,"NA/NAM" , 2108665)},
{ "+265", new CountryData(Standard,"Malawi" ,"MW/MWI" , 14268711)},
{ "+266", new CountryData(Standard,"Lesotho" ,"LS/LSO" , 2130819)},
{ "+267", new CountryData(Standard,"Botswana" ,"BW/BWA" , 1990876)},
{ "+268", new CountryData(Standard,"Swaziland" ,"SZ/SWZ" , 1123913)},
{ "+269", new CountryData(Standard,"Comoros" ,"KM/COM" , 752438)},
{ "+27", new CountryData(Standard,"SouthAfrica" ,"ZA/ZAF" , 49052489)},
{ "+290", new CountryData(Standard,"SaintHelena" ,"SH/SHN" , 7637)},
{ "+291", new CountryData(Standard,"Eritrea" ,"ER/ERI" , 5647168)},
{ "+297", new CountryData(Standard,"Aruba" ,"AW/ABW" , 103065)},
{ "+298", new CountryData(Standard,"FaroeIslands" ,"FO/FRO" , 48856)},
{ "+299", new CountryData(Standard,"Greenland" ,"GL/GRL" , 57600)},
{ "+30", new CountryData(Standard,"Greece" ,"GR/GRC" , 10737428)},
{ "+31", new CountryData(Standard,"Netherlands" ,"NL/NLD" , 16715999)},
{ "+32", new CountryData(Standard,"Belgium" ,"BE/BEL" , 10414336)},
{ "+33", new CountryData(Standard,"France" ,"FR/FRA" , 64057792)},
{ "+34", new CountryData(Standard,"Spain" ,"ES/ESP" , 40525002)},
{ "+350", new CountryData(Standard,"Gibraltar" ,"GI/GIB" , 28034)},
{ "+351", new CountryData(Standard,"Portugal" ,"PT/PRT" , 10707924)},
{ "+352", new CountryData(Standard,"Luxembourg" ,"LU/LUX" , 491775)},
{ "+353", new CountryData(Standard,"Ireland" ,"IE/IRL" , 4203200)},
{ "+354", new CountryData(Standard,"Iceland" ,"IS/IS" , 306694)},
{ "+355", new CountryData(Standard,"Albania" ,"AL/ALB" , 3639453)},
{ "+356", new CountryData(Standard,"Malta" ,"MT/MLT" , 405165)},
{ "+357", new CountryData(Standard,"Cyprus" ,"CY/CYP" , 796740)},
{ "+358", new CountryData(Standard,"Finland" ,"FI/FIN" , 5250275)},
{ "+359", new CountryData(Standard,"Bulgaria" ,"BG/BGR" , 7204687)},
{ "+36", new CountryData(Standard,"Hungary" ,"HU/HUN" , 9905596)},
{ "+370", new CountryData(Standard,"Lithuania" ,"LT/LTU" , 3555179)},
{ "+371", new CountryData(Standard,"Latvia" ,"LV/LVA" , 2231503)},
{ "+372", new CountryData(Standard,"Estonia" ,"EE/EST" , 1299371)},
{ "+373", new CountryData(Standard,"Moldova" ,"MD/MDA" , 4320748)},
{ "+374", new CountryData(Standard,"Armenia" ,"AM/ARM" , 2967004)},
{ "+375", new CountryData(Standard,"Belarus" ,"BY/BLR" , 9648533)},
{ "+376", new CountryData(Standard,"Andorra" ,"AD/AND" , 83888)},
{ "+377", new CountryData(Standard,"Monaco" ,"MC/MCO" , 32965)},
{ "+378", new CountryData(Standard,"SanMarino" ,"SM/SMR" , 30324)},
{ "+380", new CountryData(Standard,"Ukraine" ,"UA/UKR" , 45700395)},
{ "+381s", new CountryData(Standard,"Serbia" ,"RS/SRB" , 7379339)},
{ "+381", new CountryData(Standard,"Kosovo" ,"/" , 1804838)},
{ "+382", new CountryData(Standard,"Montenegro" ,"ME/MNE" , 672180)},
{ "+385", new CountryData(Standard,"Croatia" ,"HR/HRV" , 4489409)},
{ "+386", new CountryData(Standard,"Slovenia" ,"SI/SVN" , 2005692)},
{ "+387", new CountryData(Standard,"BosniaandHerzegovina" ,"BA/BIH" , 4613414)},
{ "+389", new CountryData(Standard,"Macedonia" ,"MK/MKD" , 2066718)},
{ "+39x", new CountryData(Standard,"HolySee(VaticanCity)" ,"VA/VAT" , 826)},
{ "+39", new CountryData(Standard,"Italy" ,"IT/ITA" , 58126212)},
{ "+40", new CountryData(Standard,"Romania" ,"RO/ROU" , 22215421)},
{ "+41", new CountryData(Standard,"Switzerland" ,"CH/CHE" , 7604467)},
{ "+420", new CountryData(Force__9,"CzechRepublic" ,"CZ/CZE" , 10211904)},
{ "+421", new CountryData(Standard,"Slovakia" ,"SK/SVK" , 5463046)},
{ "+423", new CountryData(Standard,"Liechtenstein" ,"LI/LIE" , 34761)},
{ "+43", new CountryData(Standard,"Austria" ,"AT/AUT" , 8210281)},
{ "+44i", new CountryData(Standard,"IsleofMan" ,"IM/IMN" , 76512)},
{ "+44", new CountryData(Standard,"UnitedKingdom" ,"GB/GBR" , 61113205)},
{ "+45", new CountryData(Standard,"Denmark" ,"DK/DNK" , 5500510)},
{ "+46", new CountryData(Standard,"Sweden" ,"SE/SWE" , 9059651)},
{ "+47", new CountryData(Standard,"Norway" ,"NO/NOR" , 4660539)},
{ "+48", new CountryData(Standard,"Poland" ,"PL/POL" , 38482919)},
{ "+49", new CountryData(Standard,"Germany" ,"DE/DEU" , 82329758)},
{ "+500", new CountryData(Standard,"FalklandIslands" ,"FK/FLK" , 3140)},
{ "+501", new CountryData(Standard,"Belize" ,"BZ/BLZ" , 307899)},
{ "+502", new CountryData(Standard,"Guatemala" ,"GT/GTM" , 13276517)},
{ "+503", new CountryData(Standard,"ElSalvador" ,"SV/SLV" , 7185218)},
{ "+504", new CountryData(Standard,"Honduras" ,"HN/HND" , 7792854)},
{ "+505", new CountryData(Standard,"Nicaragua" ,"NI/NIC" , 5891199)},
{ "+506", new CountryData(Standard,"CostaRica" ,"CR/CRC" , 4253877)},
{ "+507", new CountryData(Standard,"Panama" ,"PA/PAN" , 3360474)},
{ "+508", new CountryData(Standard,"SaintPierreandMiquelon" ,"PM/SPM" , 7051)},
{ "+509", new CountryData(Standard,"Haiti" ,"HT/HTI" , 9035536)},
{ "+51", new CountryData(Standard,"Peru" ,"PE/PER" , 29546963)},
{ "+52", new CountryData(Standard,"Mexico" ,"MX/MEX" , 111211789)},
{ "+53", new CountryData(Standard,"Cuba" ,"CU/CUB" , 11451652)},
{ "+54", new CountryData(Standard,"Argentina" ,"AR/ARG" , 40913584)},
{ "+55", new CountryData(Standard,"Brazil" ,"BR/BRA" , 198739269)},
{ "+56", new CountryData(Standard,"Chile" ,"CL/CHL" , 16601707)},
{ "+57", new CountryData(Standard,"Colombia" ,"CO/COL" , 45644023)},
{ "+58", new CountryData(Standard,"Venezuela" ,"VE/VEN" , 26814843)},
{ "+590", new CountryData(Standard,"SaintBarthelemy" ,"BL/BLM" , 7448)},
{ "+591", new CountryData(Standard,"Bolivia" ,"BO/BOL" , 9775246)},
{ "+592", new CountryData(Standard,"Guyana" ,"GY/GUY" , 772298)},
{ "+593", new CountryData(Standard,"Ecuador" ,"EC/ECU" , 14573101)},
{ "+595", new CountryData(Standard,"Paraguay" ,"PY/PRY" , 6995655)},
{ "+597", new CountryData(Standard,"Suriname" ,"SR/SUR" , 481267)},
{ "+598", new CountryData(Standard,"Uruguay" ,"UY/URY" , 3494382)},
{ "+599", new CountryData(Standard,"NetherlandsAntilles" ,"AN/ANT" , 227049)},
{ "+60", new CountryData(Standard,"Malaysia" ,"MY/MYS" , 25715819)},
{ "+61x", new CountryData(Standard,"ChristmasIsland" ,"CX/CXR" , 1402)},
{ "+61", new CountryData(Standard,"Australia" ,"AU/AUS" , 21262641)},
{ "+62", new CountryData(Standard,"Indonesia" ,"ID/IDN" , 240271522)},
{ "+63", new CountryData(Standard,"Philippines" ,"PH/PHL" , 97976603)},
{ "+64", new CountryData(Standard,"NewZealand" ,"NZ/NZL" , 4213418)},
{ "+65", new CountryData(Standard,"Singapore" ,"SG/SGP" , 4657542)},
{ "+66", new CountryData(Standard,"Thailand" ,"TH/THA" , 65905410)},
{ "+670", new CountryData(Standard,"Timor-Leste" ,"TL/TLS" , 1131612)},
{ "+672x", new CountryData(Standard,"NorfolkIsland" ,"/NFK" , 2141)},
{ "+672", new CountryData(Standard,"Antarctica" ,"AQ/ATA" , 0)},
{ "+673", new CountryData(Standard,"Brunei" ,"BN/BRN" , 388190)},
{ "+674", new CountryData(Standard,"Nauru" ,"NR/NRU" , 14019)},
{ "+675", new CountryData(Standard,"PapuaNewGuinea" ,"PG/PNG" , 6057263)},
{ "+676", new CountryData(Standard,"Tonga" ,"TO/TON" , 120898)},
{ "+677", new CountryData(Standard,"SolomonIslands" ,"SB/SLB" , 595613)},
{ "+678", new CountryData(Standard,"Vanuatu" ,"VU/VUT" , 218519)},
{ "+679", new CountryData(Standard,"Fiji" ,"FJ/FJI" , 944720)},
{ "+680", new CountryData(Standard,"Palau" ,"PW/PLW" , 20796)},
{ "+681", new CountryData(Standard,"WallisandFutuna" ,"WF/WLF" , 15289)},
{ "+682", new CountryData(Standard,"CookIslands" ,"CK/COK" , 11870)},
{ "+683", new CountryData(Standard,"Niue" ,"NU/NIU" , 1398)},
{ "+685", new CountryData(Standard,"Samoa" ,"WS/WSM" , 219998)},
{ "+686", new CountryData(Standard,"Kiribati" ,"KI/KIR" , 112850)},
{ "+687", new CountryData(Standard,"NewCaledonia" ,"NC/NCL" , 227436)},
{ "+688", new CountryData(Standard,"Tuvalu" ,"TV/TUV" , 12373)},
{ "+689", new CountryData(Standard,"FrenchPolynesia" ,"PF/PYF" , 287032)},
{ "+690", new CountryData(Standard,"Tokelau" ,"TK/TKL" , 1416)},
{ "+691", new CountryData(Standard,"Micronesia" ,"FM/FSM" , 107434)},
{ "+692", new CountryData(Standard,"MarshallIslands" ,"MH/MHL" , 64522)},
{ "+7k", new CountryData(Standard,"Kazakhstan" ,"KZ/KAZ" , 15399437)},
{ "+7", new CountryData(Standard,"Russia" ,"RU/RUS" , 140041247)},
{ "+81", new CountryData(Standard,"Japan" ,"JP/JPN" , 127078679)},
{ "+82", new CountryData(Standard,"SouthKorea" ,"KR/KOR" , 48508972)},
{ "+84", new CountryData(Standard,"Vietnam" ,"VN/VNM" , 86967524)},
{ "+850", new CountryData(Standard,"NorthKorea" ,"KP/PRK" , 22665345)},
{ "+852", new CountryData(Standard,"HongKong" ,"HK/HKG" , 7055071)},
{ "+853", new CountryData(Standard,"Macau" ,"MO/MAC" , 559846)},
{ "+855", new CountryData(Standard,"Cambodia" ,"KH/KHM" , 14494293)},
{ "+856", new CountryData(Standard,"Laos" ,"LA/LAO" , 6834942)},
{ "+86", new CountryData(Standard,"China" ,"CN/CHN" ,1338612968)},
{ "+870", new CountryData(Standard,"PitcairnIslands" ,"PN/PCN" , 48)},
{ "+880", new CountryData(Standard,"Bangladesh" ,"BD/BGD" , 156050883)},
{ "+886", new CountryData(Standard,"Taiwan" ,"TW/TWN" , 22974347)},
{ "+90", new CountryData(Standard,"Turkey" ,"TR/TUR" , 76805524)},
{ "+91", new CountryData(Standard,"India" ,"IN/IND" ,1166079217)},
{ "+92", new CountryData(Standard,"Pakistan" ,"PK/PAK" , 176242949)},
{ "+93", new CountryData(Standard,"Afghanistan" ,"AF/AFG" , 28396000)},
{ "+94", new CountryData(Standard,"SriLanka" ,"LK/LKA" , 21324791)},
{ "+95", new CountryData(Standard,"Burma(Myanmar)" ,"MM/MMR" , 48137741)},
{ "+960", new CountryData(Standard,"Maldives" ,"MV/MDV" , 396334)},
{ "+961", new CountryData(Standard,"Lebanon" ,"LB/LBN" , 4017095)},
{ "+962", new CountryData(Standard,"Jordan" ,"JO/JOR" , 6342948)},
{ "+963", new CountryData(Standard,"Syria" ,"SY/SYR" , 20178485)},
{ "+964", new CountryData(Standard,"Iraq" ,"IQ/IRQ" , 28945657)},
{ "+965", new CountryData(Standard,"Kuwait" ,"KW/KWT" , 2691158)},
{ "+966", new CountryData(Standard,"SaudiArabia" ,"SA/SAU" , 28686633)},
{ "+967", new CountryData(Standard,"Yemen" ,"YE/YEM" , 23822783)},
{ "+968", new CountryData(Standard,"Oman" ,"OM/OMN" , 3418085)},
{ "+970w", new CountryData(Standard,"WestBank" ,"/" , 2461267)},
{ "+970", new CountryData(Standard,"GazaStrip" ,"/" , 1551859)},
{ "+971", new CountryData(Standard,"UnitedArabEmirates" ,"AE/ARE" , 4798491)},
{ "+972", new CountryData(Standard,"Israel" ,"IL/ISR" , 7233701)},
{ "+973", new CountryData(Standard,"Bahrain" ,"BH/BHR" , 727785)},
{ "+974", new CountryData(Standard,"Qatar" ,"QA/QAT" , 833285)},
{ "+975", new CountryData(Standard,"Bhutan" ,"BT/BTN" , 691141)},
{ "+976", new CountryData(Standard,"Mongolia" ,"MN/MNG" , 3041142)},
{ "+977", new CountryData(Standard,"Nepal" ,"NP/NPL" , 28563377)},
{ "+98", new CountryData(Standard,"Iran" ,"IR/IRN" , 66429284)},
{ "+992", new CountryData(Standard,"Tajikistan" ,"TJ/TJK" , 7349145)},
{ "+993", new CountryData(Standard,"Turkmenistan" ,"TM/TKM" , 4884887)},
{ "+994", new CountryData(Standard,"Azerbaijan" ,"AZ/AZE" , 8238672)},
{ "+995", new CountryData(Standard,"Georgia" ,"GE/GEO" , 4615807)},
{ "+996", new CountryData(Standard,"Kyrgyzstan" ,"KG/KGZ" , 5431747)},
{ "+998", new CountryData(Standard,"Uzbekistan" ,"UZ/UZB" , 27606007)},
{ "+s", new CountryData(Standard,"Svalbard" ,"SJ/SJM" , 2116)}};

}

}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

9:27:45 02.01.2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace Hamon
{
/// <summary>
/// Kdyz uz, tak poradne a bez bezducheho tlaceni 9 cifer
/// </summary>
class Program
{
static void Main(string[] args)
{
string[] num = new string[] { "+420 123 456 789", "+352123 456789", "123456789", "12345", "+420123 456789 1234567", "+1123456789" };
foreach (string s in num)
Console.WriteLine(CountryData.Hamoun(s));
}
public class CountryData
{
public static string Hamoun(string num)
{
num = Regex.Replace(num, @"[^+^0-9]+", "");
var code = "+420";
foreach (var c in data.Keys)
{
if (num.StartsWith(c))
{
num = num.Replace(c, "");
code = c;
break;
}
}
return data[code].z_fmt(code, num);
}

delegate string Formatter(string code, string number);
string z_country;
string z_mask;
int z_forcedDigits;
string z_code;
string z_abbrev;
int z_popul;
Formatter z_fmt;
CountryData(Formatter fmt, string country, string abbrev, int popul)
{
z_country = country;
z_abbrev = abbrev;
z_fmt = fmt;
}
static string Standard(string code, string number) { return Mask(code, " *** *** ***", number); }
static string Force__9(string code, string number) { return Mask(code, " *** *** ***",Force( number,9)); }
static string US_Rules(string code, string number) { return Mask(code, "-***-****-***",number); }
static string Mask(string code, string mask, string number)
{
var sb = new StringBuilder(code);
int i = 0;
foreach (var c in mask)
{
if (c == '*')
{
sb.Append(number[i++]);
if (i >= number.Length) break;
}
else sb.Append(c);
}
for (; i < number.Length;i++ )sb.Append(number[i]);
return sb.ToString();
}
static string Force(string num, int digits)
{
if (num.Length < digits) return num.PadLeft(digits, '0'); // what a stupidity Hamoun asks for
if (num.Length > digits) return num.Substring(0, digits);
return num;
}
static Dictionary<string, CountryData> data = new Dictionary<string, CountryData>{
{ "+93", new CountryData(Standard,"Afghanistan" ,"AF/AFG" , 28396000)},
{ "+355", new CountryData(Standard,"Albania" ,"AL/ALB" , 3639453)},
{ "+213", new CountryData(Standard,"Algeria" ,"DZ/DZA" , 34178188)},
{ "+1684", new CountryData(Standard,"AmericanSamoa" ,"AS/ASM" , 65628)},
{ "+376", new CountryData(Standard,"Andorra" ,"AD/AND" , 83888)},
{ "+244", new CountryData(Standard,"Angola" ,"AO/AGO" , 12799293)},
{ "+1264", new CountryData(Standard,"Anguilla" ,"AI/AIA" , 14436)},
{ "+672", new CountryData(Standard,"Antarctica" ,"AQ/ATA" , 0)},
{ "+1268", new CountryData(Standard,"AntiguaandBarbuda" ,"AG/ATG" , 85632)},
{ "+54", new CountryData(Standard,"Argentina" ,"AR/ARG" , 40913584)},
{ "+374", new CountryData(Standard,"Armenia" ,"AM/ARM" , 2967004)},
{ "+297", new CountryData(Standard,"Aruba" ,"AW/ABW" , 103065)},
{ "+61", new CountryData(Standard,"Australia" ,"AU/AUS" , 21262641)},
{ "+43", new CountryData(Standard,"Austria" ,"AT/AUT" , 8210281)},
{ "+994", new CountryData(Standard,"Azerbaijan" ,"AZ/AZE" , 8238672)},
{ "+1242", new CountryData(Standard,"Bahamas" ,"BS/BHS" , 309156)},
{ "+973", new CountryData(Standard,"Bahrain" ,"BH/BHR" , 727785)},
{ "+880", new CountryData(Standard,"Bangladesh" ,"BD/BGD" , 156050883)},
{ "+1246", new CountryData(Standard,"Barbados" ,"BB/BRB" , 284589)},
{ "+375", new CountryData(Standard,"Belarus" ,"BY/BLR" , 9648533)},
{ "+32", new CountryData(Standard,"Belgium" ,"BE/BEL" , 10414336)},
{ "+501", new CountryData(Standard,"Belize" ,"BZ/BLZ" , 307899)},
{ "+229", new CountryData(Standard,"Benin" ,"BJ/BEN" , 8791832)},
{ "+1441", new CountryData(Standard,"Bermuda" ,"BM/BMU" , 67837)},
{ "+975", new CountryData(Standard,"Bhutan" ,"BT/BTN" , 691141)},
{ "+591", new CountryData(Standard,"Bolivia" ,"BO/BOL" , 9775246)},
{ "+387", new CountryData(Standard,"BosniaandHerzegovina" ,"BA/BIH" , 4613414)},
{ "+267", new CountryData(Standard,"Botswana" ,"BW/BWA" , 1990876)},
{ "+55", new CountryData(Standard,"Brazil" ,"BR/BRA" , 198739269)},
{ "+1284", new CountryData(Standard,"BritishVirginIslands" ,"VG/VGB" , 24491)},
{ "+673", new CountryData(Standard,"Brunei" ,"BN/BRN" , 388190)},
{ "+359", new CountryData(Standard,"Bulgaria" ,"BG/BGR" , 7204687)},
{ "+226", new CountryData(Standard,"BurkinaFaso" ,"BF/BFA" , 15746232)},
{ "+95", new CountryData(Standard,"Burma(Myanmar)" ,"MM/MMR" , 48137741)},
{ "+257", new CountryData(Standard,"Burundi" ,"BI/BDI" , 8988091)},
{ "+855", new CountryData(Standard,"Cambodia" ,"KH/KHM" , 14494293)},
{ "+237", new CountryData(Standard,"Cameroon" ,"CM/CMR" , 18879301)},
{ "+1c", new CountryData(Standard,"Canada" ,"CA/CAN" , 33487208)},
{ "+238", new CountryData(Standard,"CapeVerde" ,"CV/CPV" , 429474)},
{ "+1345", new CountryData(Standard,"CaymanIslands" ,"KY/CYM" , 49035)},
{ "+236", new CountryData(Standard,"CentralAfricanRepublic" ,"CF/CAF" , 4511488)},
{ "+235", new CountryData(Standard,"Chad" ,"TD/TCD" , 10329208)},
{ "+56", new CountryData(Standard,"Chile" ,"CL/CHL" , 16601707)},
{ "+86", new CountryData(Standard,"China" ,"CN/CHN" ,1338612968)},
{ "+61x", new CountryData(Standard,"ChristmasIsland" ,"CX/CXR" , 1402)},
{ "+57", new CountryData(Standard,"Colombia" ,"CO/COL" , 45644023)},
{ "+269", new CountryData(Standard,"Comoros" ,"KM/COM" , 752438)},
{ "+682", new CountryData(Standard,"CookIslands" ,"CK/COK" , 11870)},
{ "+506", new CountryData(Standard,"CostaRica" ,"CR/CRC" , 4253877)},
{ "+385", new CountryData(Standard,"Croatia" ,"HR/HRV" , 4489409)},
{ "+53", new CountryData(Standard,"Cuba" ,"CU/CUB" , 11451652)},
{ "+357", new CountryData(Standard,"Cyprus" ,"CY/CYP" , 796740)},
{ "+420", new CountryData(Force__9,"CzechRepublic" ,"CZ/CZE" , 10211904)},
{ "+243", new CountryData(Standard,"DemocraticRepublicoftheCongo","CD/COD" , 68692542)},
{ "+45", new CountryData(Standard,"Denmark" ,"DK/DNK" , 5500510)},
{ "+253", new CountryData(Standard,"Djibouti" ,"DJ/DJI" , 516055)},
{ "+1767", new CountryData(Standard,"Dominica" ,"DM/DMA" , 72660)},
{ "+1809", new CountryData(Standard,"DominicanRepublic" ,"DO/DOM" , 9650054)},
{ "+593", new CountryData(Standard,"Ecuador" ,"EC/ECU" , 14573101)},
{ "+20", new CountryData(Standard,"Egypt" ,"EG/EGY" , 83082869)},
{ "+503", new CountryData(Standard,"ElSalvador" ,"SV/SLV" , 7185218)},
{ "+240", new CountryData(Standard,"EquatorialGuinea" ,"GQ/GNQ" , 633441)},
{ "+291", new CountryData(Standard,"Eritrea" ,"ER/ERI" , 5647168)},
{ "+372", new CountryData(Standard,"Estonia" ,"EE/EST" , 1299371)},
{ "+251", new CountryData(Standard,"Ethiopia" ,"ET/ETH" , 85237338)},
{ "+500", new CountryData(Standard,"FalklandIslands" ,"FK/FLK" , 3140)},
{ "+298", new CountryData(Standard,"FaroeIslands" ,"FO/FRO" , 48856)},
{ "+679", new CountryData(Standard,"Fiji" ,"FJ/FJI" , 944720)},
{ "+358", new CountryData(Standard,"Finland" ,"FI/FIN" , 5250275)},
{ "+33", new CountryData(Standard,"France" ,"FR/FRA" , 64057792)},
{ "+689", new CountryData(Standard,"FrenchPolynesia" ,"PF/PYF" , 287032)},
{ "+241", new CountryData(Standard,"Gabon" ,"GA/GAB" , 1514993)},
{ "+220", new CountryData(Standard,"Gambia" ,"GM/GMB" , 1782893)},
{ "+970", new CountryData(Standard,"GazaStrip" ,"/" , 1551859)},
{ "+995", new CountryData(Standard,"Georgia" ,"GE/GEO" , 4615807)},
{ "+49", new CountryData(Standard,"Germany" ,"DE/DEU" , 82329758)},
{ "+233", new CountryData(Standard,"Ghana" ,"GH/GHA" , 23832495)},
{ "+350", new CountryData(Standard,"Gibraltar" ,"GI/GIB" , 28034)},
{ "+30", new CountryData(Standard,"Greece" ,"GR/GRC" , 10737428)},
{ "+299", new CountryData(Standard,"Greenland" ,"GL/GRL" , 57600)},
{ "+1473", new CountryData(Standard,"Grenada" ,"GD/GRD" , 90739)},
{ "+1671", new CountryData(Standard,"Guam" ,"GU/GUM" , 160595)},
{ "+502", new CountryData(Standard,"Guatemala" ,"GT/GTM" , 13276517)},
{ "+224", new CountryData(Standard,"Guinea" ,"GN/GIN" , 10057975)},
{ "+245", new CountryData(Standard,"Guinea-Bissau" ,"GW/GNB" , 1533964)},
{ "+592", new CountryData(Standard,"Guyana" ,"GY/GUY" , 772298)},
{ "+509", new CountryData(Standard,"Haiti" ,"HT/HTI" , 9035536)},
{ "+39x", new CountryData(Standard,"HolySee(VaticanCity)" ,"VA/VAT" , 826)},
{ "+504", new CountryData(Standard,"Honduras" ,"HN/HND" , 7792854)},
{ "+852", new CountryData(Standard,"HongKong" ,"HK/HKG" , 7055071)},
{ "+36", new CountryData(Standard,"Hungary" ,"HU/HUN" , 9905596)},
{ "+354", new CountryData(Standard,"Iceland" ,"IS/IS" , 306694)},
{ "+91", new CountryData(Standard,"India" ,"IN/IND" ,1166079217)},
{ "+62", new CountryData(Standard,"Indonesia" ,"ID/IDN" , 240271522)},
{ "+98", new CountryData(Standard,"Iran" ,"IR/IRN" , 66429284)},
{ "+964", new CountryData(Standard,"Iraq" ,"IQ/IRQ" , 28945657)},
{ "+353", new CountryData(Standard,"Ireland" ,"IE/IRL" , 4203200)},
{ "+44i", new CountryData(Standard,"IsleofMan" ,"IM/IMN" , 76512)},
{ "+972", new CountryData(Standard,"Israel" ,"IL/ISR" , 7233701)},
{ "+39", new CountryData(Standard,"Italy" ,"IT/ITA" , 58126212)},
{ "+225", new CountryData(Standard,"IvoryCoast" ,"CI/CIV" , 20617068)},
{ "+1876", new CountryData(Standard,"Jamaica" ,"JM/JAM" , 2825928)},
{ "+81", new CountryData(Standard,"Japan" ,"JP/JPN" , 127078679)},
{ "+962", new CountryData(Standard,"Jordan" ,"JO/JOR" , 6342948)},
{ "+7k", new CountryData(Standard,"Kazakhstan" ,"KZ/KAZ" , 15399437)},
{ "+254", new CountryData(Standard,"Kenya" ,"KE/KEN" , 39002772)},
{ "+686", new CountryData(Standard,"Kiribati" ,"KI/KIR" , 112850)},
{ "+381", new CountryData(Standard,"Kosovo" ,"/" , 1804838)},
{ "+965", new CountryData(Standard,"Kuwait" ,"KW/KWT" , 2691158)},
{ "+996", new CountryData(Standard,"Kyrgyzstan" ,"KG/KGZ" , 5431747)},
{ "+856", new CountryData(Standard,"Laos" ,"LA/LAO" , 6834942)},
{ "+371", new CountryData(Standard,"Latvia" ,"LV/LVA" , 2231503)},
{ "+961", new CountryData(Standard,"Lebanon" ,"LB/LBN" , 4017095)},
{ "+266", new CountryData(Standard,"Lesotho" ,"LS/LSO" , 2130819)},
{ "+231", new CountryData(Standard,"Liberia" ,"LR/LBR" , 3441790)},
{ "+218", new CountryData(Standard,"Libya" ,"LY/LBY" , 6310434)},
{ "+423", new CountryData(Standard,"Liechtenstein" ,"LI/LIE" , 34761)},
{ "+370", new CountryData(Standard,"Lithuania" ,"LT/LTU" , 3555179)},
{ "+352", new CountryData(Standard,"Luxembourg" ,"LU/LUX" , 491775)},
{ "+853", new CountryData(Standard,"Macau" ,"MO/MAC" , 559846)},
{ "+389", new CountryData(Standard,"Macedonia" ,"MK/MKD" , 2066718)},
{ "+261", new CountryData(Standard,"Madagascar" ,"MG/MDG" , 20653556)},
{ "+265", new CountryData(Standard,"Malawi" ,"MW/MWI" , 14268711)},
{ "+60", new CountryData(Standard,"Malaysia" ,"MY/MYS" , 25715819)},
{ "+960", new CountryData(Standard,"Maldives" ,"MV/MDV" , 396334)},
{ "+223", new CountryData(Standard,"Mali" ,"ML/MLI" , 12666987)},
{ "+356", new CountryData(Standard,"Malta" ,"MT/MLT" , 405165)},
{ "+692", new CountryData(Standard,"MarshallIslands" ,"MH/MHL" , 64522)},
{ "+222", new CountryData(Standard,"Mauritania" ,"MR/MRT" , 3129486)},
{ "+230", new CountryData(Standard,"Mauritius" ,"MU/MUS" , 1284264)},
{ "+262", new CountryData(Standard,"Mayotte" ,"YT/MYT" , 223765)},
{ "+52", new CountryData(Standard,"Mexico" ,"MX/MEX" , 111211789)},
{ "+691", new CountryData(Standard,"Micronesia" ,"FM/FSM" , 107434)},
{ "+373", new CountryData(Standard,"Moldova" ,"MD/MDA" , 4320748)},
{ "+377", new CountryData(Standard,"Monaco" ,"MC/MCO" , 32965)},
{ "+976", new CountryData(Standard,"Mongolia" ,"MN/MNG" , 3041142)},
{ "+382", new CountryData(Standard,"Montenegro" ,"ME/MNE" , 672180)},
{ "+1664", new CountryData(Standard,"Montserrat" ,"MS/MSR" , 5097)},
{ "+212", new CountryData(Standard,"Morocco" ,"MA/MAR" , 34859364)},
{ "+258", new CountryData(Standard,"Mozambique" ,"MZ/MOZ" , 21669278)},
{ "+264", new CountryData(Standard,"Namibia" ,"NA/NAM" , 2108665)},
{ "+674", new CountryData(Standard,"Nauru" ,"NR/NRU" , 14019)},
{ "+977", new CountryData(Standard,"Nepal" ,"NP/NPL" , 28563377)},
{ "+31", new CountryData(Standard,"Netherlands" ,"NL/NLD" , 16715999)},
{ "+599", new CountryData(Standard,"NetherlandsAntilles" ,"AN/ANT" , 227049)},
{ "+687", new CountryData(Standard,"NewCaledonia" ,"NC/NCL" , 227436)},
{ "+64", new CountryData(Standard,"NewZealand" ,"NZ/NZL" , 4213418)},
{ "+505", new CountryData(Standard,"Nicaragua" ,"NI/NIC" , 5891199)},
{ "+227", new CountryData(Standard,"Niger" ,"NE/NER" , 15306252)},
{ "+234", new CountryData(Standard,"Nigeria" ,"NG/NGA" , 149229090)},
{ "+683", new CountryData(Standard,"Niue" ,"NU/NIU" , 1398)},
{ "+672x", new CountryData(Standard,"NorfolkIsland" ,"/NFK" , 2141)},
{ "+850", new CountryData(Standard,"NorthKorea" ,"KP/PRK" , 22665345)},
{ "+1670", new CountryData(Standard,"NorthernMarianaIslands" ,"MP/MNP" , 88662)},
{ "+47", new CountryData(Standard,"Norway" ,"NO/NOR" , 4660539)},
{ "+968", new CountryData(Standard,"Oman" ,"OM/OMN" , 3418085)},
{ "+92", new CountryData(Standard,"Pakistan" ,"PK/PAK" , 176242949)},
{ "+680", new CountryData(Standard,"Palau" ,"PW/PLW" , 20796)},
{ "+507", new CountryData(Standard,"Panama" ,"PA/PAN" , 3360474)},
{ "+675", new CountryData(Standard,"PapuaNewGuinea" ,"PG/PNG" , 6057263)},
{ "+595", new CountryData(Standard,"Paraguay" ,"PY/PRY" , 6995655)},
{ "+51", new CountryData(Standard,"Peru" ,"PE/PER" , 29546963)},
{ "+63", new CountryData(Standard,"Philippines" ,"PH/PHL" , 97976603)},
{ "+870", new CountryData(Standard,"PitcairnIslands" ,"PN/PCN" , 48)},
{ "+48", new CountryData(Standard,"Poland" ,"PL/POL" , 38482919)},
{ "+351", new CountryData(Standard,"Portugal" ,"PT/PRT" , 10707924)},
{ "+1x", new CountryData(Standard,"PuertoRico" ,"PR/PRI" , 3971020)},
{ "+974", new CountryData(Standard,"Qatar" ,"QA/QAT" , 833285)},
{ "+242", new CountryData(Standard,"RepublicoftheCongo" ,"CG/COG" , 4012809)},
{ "+40", new CountryData(Standard,"Romania" ,"RO/ROU" , 22215421)},
{ "+7", new CountryData(Standard,"Russia" ,"RU/RUS" , 140041247)},
{ "+250", new CountryData(Standard,"Rwanda" ,"RW/RWA" , 10473282)},
{ "+590", new CountryData(Standard,"SaintBarthelemy" ,"BL/BLM" , 7448)},
{ "+290", new CountryData(Standard,"SaintHelena" ,"SH/SHN" , 7637)},
{ "+1869", new CountryData(Standard,"SaintKittsandNevis" ,"KN/KNA" , 40131)},
{ "+1758", new CountryData(Standard,"SaintLucia" ,"LC/LCA" , 160267)},
{ "+1599", new CountryData(Standard,"SaintMartin" ,"MF/MAF" , 29820)},
{ "+508", new CountryData(Standard,"SaintPierreandMiquelon" ,"PM/SPM" , 7051)},
{ "+1784", new CountryData(Standard,"SaintVincentandtheGrenadines","VC/VCT" , 104574)},
{ "+685", new CountryData(Standard,"Samoa" ,"WS/WSM" , 219998)},
{ "+378", new CountryData(Standard,"SanMarino" ,"SM/SMR" , 30324)},
{ "+239", new CountryData(Standard,"SaoTomeandPrincipe" ,"ST/STP" , 212679)},
{ "+966", new CountryData(Standard,"SaudiArabia" ,"SA/SAU" , 28686633)},
{ "+221", new CountryData(Standard,"Senegal" ,"SN/SEN" , 13711597)},
{ "+381s", new CountryData(Standard,"Serbia" ,"RS/SRB" , 7379339)},
{ "+248", new CountryData(Standard,"Seychelles" ,"SC/SYC" , 87476)},
{ "+232", new CountryData(Standard,"SierraLeone" ,"SL/SLE" , 6440053)},
{ "+65", new CountryData(Standard,"Singapore" ,"SG/SGP" , 4657542)},
{ "+421", new CountryData(Standard,"Slovakia" ,"SK/SVK" , 5463046)},
{ "+386", new CountryData(Standard,"Slovenia" ,"SI/SVN" , 2005692)},
{ "+677", new CountryData(Standard,"SolomonIslands" ,"SB/SLB" , 595613)},
{ "+252", new CountryData(Standard,"Somalia" ,"SO/SOM" , 9832017)},
{ "+27", new CountryData(Standard,"SouthAfrica" ,"ZA/ZAF" , 49052489)},
{ "+82", new CountryData(Standard,"SouthKorea" ,"KR/KOR" , 48508972)},
{ "+34", new CountryData(Standard,"Spain" ,"ES/ESP" , 40525002)},
{ "+94", new CountryData(Standard,"SriLanka" ,"LK/LKA" , 21324791)},
{ "+249", new CountryData(Standard,"Sudan" ,"SD/SDN" , 41087825)},
{ "+597", new CountryData(Standard,"Suriname" ,"SR/SUR" , 481267)},
{ "+s", new CountryData(Standard,"Svalbard" ,"SJ/SJM" , 2116)},
{ "+268", new CountryData(Standard,"Swaziland" ,"SZ/SWZ" , 1123913)},
{ "+46", new CountryData(Standard,"Sweden" ,"SE/SWE" , 9059651)},
{ "+41", new CountryData(Standard,"Switzerland" ,"CH/CHE" , 7604467)},
{ "+963", new CountryData(Standard,"Syria" ,"SY/SYR" , 20178485)},
{ "+886", new CountryData(Standard,"Taiwan" ,"TW/TWN" , 22974347)},
{ "+992", new CountryData(Standard,"Tajikistan" ,"TJ/TJK" , 7349145)},
{ "+255", new CountryData(Standard,"Tanzania" ,"TZ/TZA" , 41048532)},
{ "+66", new CountryData(Standard,"Thailand" ,"TH/THA" , 65905410)},
{ "+670", new CountryData(Standard,"Timor-Leste" ,"TL/TLS" , 1131612)},
{ "+228", new CountryData(Standard,"Togo" ,"TG/TGO" , 6019877)},
{ "+690", new CountryData(Standard,"Tokelau" ,"TK/TKL" , 1416)},
{ "+676", new CountryData(Standard,"Tonga" ,"TO/TON" , 120898)},
{ "+1868", new CountryData(Standard,"TrinidadandTobago" ,"TT/TTO" , 1229953)},
{ "+216", new CountryData(Standard,"Tunisia" ,"TN/TUN" , 10486339)},
{ "+90", new CountryData(Standard,"Turkey" ,"TR/TUR" , 76805524)},
{ "+993", new CountryData(Standard,"Turkmenistan" ,"TM/TKM" , 4884887)},
{ "+1649", new CountryData(Standard,"TurksandCaicosIslands" ,"TC/TCA" , 22942)},
{ "+688", new CountryData(Standard,"Tuvalu" ,"TV/TUV" , 12373)},
{ "+256", new CountryData(Standard,"Uganda" ,"UG/UGA" , 32369558)},
{ "+380", new CountryData(Standard,"Ukraine" ,"UA/UKR" , 45700395)},
{ "+971", new CountryData(Standard,"UnitedArabEmirates" ,"AE/ARE" , 4798491)},
{ "+44", new CountryData(Standard,"UnitedKingdom" ,"GB/GBR" , 61113205)},
{ "+1", new CountryData(US_Rules,"UnitedStates" ,"US/USA" , 307212123)},
{ "+598", new CountryData(Standard,"Uruguay" ,"UY/URY" , 3494382)},
{ "+1340", new CountryData(Standard,"USVirginIslands" ,"VI/VIR" , 109825)},
{ "+998", new CountryData(Standard,"Uzbekistan" ,"UZ/UZB" , 27606007)},
{ "+678", new CountryData(Standard,"Vanuatu" ,"VU/VUT" , 218519)},
{ "+58", new CountryData(Standard,"Venezuela" ,"VE/VEN" , 26814843)},
{ "+84", new CountryData(Standard,"Vietnam" ,"VN/VNM" , 86967524)},
{ "+681", new CountryData(Standard,"WallisandFutuna" ,"WF/WLF" , 15289)},
{ "+970w", new CountryData(Standard,"WestBank" ,"/" , 2461267)},
{ "+967", new CountryData(Standard,"Yemen" ,"YE/YEM" , 23822783)},
{ "+260", new CountryData(Standard,"Zambia" ,"ZM/ZMB" , 11862740)},
{ "+263", new CountryData(Standard,"Zimbabwe" ,"ZW/ZWE" , 11392629)}};

}
}
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

16:49:21 01.01.2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Hamon
{
/// <summary>
/// Kdyz uz, tak poradne a bez bezducheho tlaceni 9 cifer
/// </summary>
class Program
{
static void Main(string[] args)
{
string[] num = new string[] { "+420 123 456 789", "+352123 456789", "123456789", "12345", "+420123 456789 1234567","+1123456789" };
foreach (string s in num)
Console.WriteLine(CountryData.Hamoun(s));
}
public class CountryData
{
string z_country;
string z_mask;
int z_forcedDigits;
string z_code;
public CountryData(string mask, int forcedDigits, string country, string abbrev, string code, string popul, string area, string gdp)
{
z_country = country;
z_mask = mask;
z_forcedDigits = forcedDigits;
z_code = code;
}
public static string Hamoun(string unformatted)
{
var num = Regex.Replace(unformatted, @"[^+^0-9]+", "");
var code = "+420";
foreach (var c in data.Keys)
{
if (unformatted.StartsWith(c))
{
num = num.Replace(c, "");
code = c;
break;
}
}
return data[code].Formatted(num);
//return code + " " + Regex.Replace(num.PadLeft(9,'0'), @"(\d{3})(\d{3})(\d{3})", "$1 $2 $3") +": "+ data[code].z_country;
}
string Formatted(string num)
{
if (z_forcedDigits > 1)
{
if (num.Length > z_forcedDigits) num = num.Substring(0, z_forcedDigits);
else num = num.PadLeft(z_forcedDigits, '0');
}
var sb = new StringBuilder("+"+z_code);
int i = 0;
foreach (var c in z_mask)
{
if (c == '*')
{
sb.Append(num[i++]);
if (i >= num.Length) break;
}
else sb.Append(c);
}
return sb.ToString();
}
static Dictionary<string, CountryData> data = new Dictionary<string, CountryData>{
{"+93",new CountryData(" *** *** *** ***",0,"Afghanistan","AF/AFG","93","28,396,000(43)","652,230(42)","22.27Billion(114)")},
{"+355",new CountryData(" *** *** *** ***",0,"Albania","AL/ALB","355","3,639,453(129)","28,748(145)","21.81Billion(116)")},
{"+213",new CountryData(" *** *** *** ***",0,"Algeria","DZ/DZA","213","34,178,188(36)","2,381,741(12)","232.9Billion(48)")},
{"+1684",new CountryData(" *** *** *** ***",0,"AmericanSamoa","AS/ASM","1684","65,628(204)","199(215)","575.3Million(210)")},
{"+376",new CountryData(" *** *** *** ***",0,"Andorra","AD/AND","376","83,888(200)","468(197)","3.66Billion(166)")},
{"+244",new CountryData(" *** *** *** ***",0,"Angola","AO/AGO","244","12,799,293(69)","1,246,700(24)","110.3Billion(62)")},
{"+1264",new CountryData(" *** *** *** ***",0,"Anguilla","AI/AIA","1264","14,436(219)","91(224)","108.9Million(218)")},
{"+672",new CountryData(" *** *** *** ***",0,"Antarctica","AQ/ATA","672","0(236)","14,000,000(2)","0(228)")},
{"+1268",new CountryData(" *** *** *** ***",0,"AntiguaandBarbuda","AG/ATG","1268","85,632(199)","443(201)","1.657Billion(188)")},
{"+54",new CountryData(" *** *** *** ***",0,"Argentina","AR/ARG","54","40,913,584(31)","2,780,400(9)","573.9Billion(23)")},
{"+374",new CountryData(" *** *** *** ***",0,"Armenia","AM/ARM","374","2,967,004(137)","29,743(143)","18.77Billion(125)")},
{"+297",new CountryData(" *** *** *** ***",0,"Aruba","AW/ABW","297","103,065(194)","180(217)","2.258Billion(180)")},
{"+61",new CountryData(" *** *** *** ***",0,"Australia","AU/AUS","61","21,262,641(54)","7,741,220(7)","800.2Billion(18)")},
{"+43",new CountryData(" *** *** *** ***",0,"Austria","AT/AUT","43","8,210,281(92)","83,871(114)","329.5Billion(36)")},
{"+994",new CountryData(" *** *** *** ***",0,"Azerbaijan","AZ/AZE","994","8,238,672(91)","86,600(113)","77.61Billion(76)")},
{"+1242",new CountryData(" *** *** *** ***",0,"Bahamas","BS/BHS","1242","309,156(176)","13,880(161)","9.093Billion(151)")},
{"+973",new CountryData(" *** *** *** ***",0,"Bahrain","BH/BHR","973","727,785(162)","741(191)","26.82Billion(111)")},
{"+880",new CountryData(" *** *** *** ***",0,"Bangladesh","BD/BGD","880","156,050,883(7)","143,998(95)","224Billion(49)")},
{"+1246",new CountryData(" *** *** *** ***",0,"Barbados","BB/BRB","1246","284,589(180)","430(202)","5.425Billion(156)")},
{"+375",new CountryData(" *** *** *** ***",0,"Belarus","BY/BLR","375","9,648,533(86)","207,600(86)","114.1Billion(61)")},
{"+32",new CountryData(" *** *** *** ***",0,"Belgium","BE/BEL","32","10,414,336(78)","30,528(141)","389.3Billion(29)")},
{"+501",new CountryData(" *** *** *** ***",0,"Belize","BZ/BLZ","501","307,899(177)","22,966(152)","2.536Billion(176)")},
{"+229",new CountryData(" *** *** *** ***",0,"Benin","BJ/BEN","229","8,791,832(90)","112,622(102)","12.83Billion(138)")},
{"+1441",new CountryData(" *** *** *** ***",0,"Bermuda","BM/BMU","1441","67,837(203)","54(226)","4.5Billion(161)")},
{"+975",new CountryData(" *** *** *** ***",0,"Bhutan","BT/BTN","975","691,141(163)","38,394(137)","3.524Billion(168)")},
{"+591",new CountryData(" *** *** *** ***",0,"Bolivia","BO/BOL","591","9,775,246(84)","1,098,581(29)","43.27Billion(91)")},
{"+387",new CountryData(" *** *** *** ***",0,"BosniaandHerzegovina","BA/BIH","387","4,613,414(119)","51,197(129)","29.7Billion(105)")},
{"+267",new CountryData(" *** *** *** ***",0,"Botswana","BW/BWA","267","1,990,876(146)","581,730(48)","27.06Billion(110)")},
{"+55",new CountryData(" *** *** *** ***",0,"Brazil","BR/BRA","55","198,739,269(5)","8,514,877(6)","1.993Trillion(9)")},
{"+1284",new CountryData(" *** *** *** ***",0,"BritishVirginIslands","VG/VGB","1284","24,491(215)","151(219)","853.4Million(205)")},
{"+673",new CountryData(" *** *** *** ***",0,"Brunei","BN/BRN","673","388,190(175)","5,765(173)","20.25Billion(121)")},
{"+359",new CountryData(" *** *** *** ***",0,"Bulgaria","BG/BGR","359","7,204,687(98)","110,879(105)","93.75Billion(67)")},
{"+226",new CountryData(" *** *** *** ***",0,"BurkinaFaso","BF/BFA","226","15,746,232(61)","274,200(75)","17.82Billion(127)")},
{"+95",new CountryData(" *** *** *** ***",0,"Burma(Myanmar)","MM/MMR","95","48,137,741(26)","676,578(41)","55.13Billion(86)")},
{"+257",new CountryData(" *** *** *** ***",0,"Burundi","BI/BDI","257","8,988,091(89)","27,830(147)","3.102Billion(172)")},
{"+855",new CountryData(" *** *** *** ***",0,"Cambodia","KH/KHM","855","14,494,293(65)","181,035(90)","27.94Billion(108)")},
{"+237",new CountryData(" *** *** *** ***",0,"Cameroon","CM/CMR","237","18,879,301(58)","475,440(54)","42.75Billion(93)")},
{"+1c",new CountryData(" *** *** *** ***",0,"Canada","CA/CAN","1","33,487,208(37)","9,984,670(3)","1.3Trillion(14)")},
{"+238",new CountryData(" *** *** *** ***",0,"CapeVerde","CV/CPV","238","429,474(171)","4,033(176)","1.626Billion(189)")},
{"+1345",new CountryData(" *** *** *** ***",0,"CaymanIslands","KY/CYM","1345","49,035(207)","264(210)","1.939Billion(181)")},
{"+236",new CountryData(" *** *** *** ***",0,"CentralAfricanRepublic","CF/CAF","236","4,511,488(120)","622,984(45)","3.198Billion(170)")},
{"+235",new CountryData(" *** *** *** ***",0,"Chad","TD/TCD","235","10,329,208(79)","1,284,000(22)","15.86Billion(130)")},
{"+56",new CountryData(" *** *** *** ***",0,"Chile","CL/CHL","56","16,601,707(60)","756,102(39)","244.5Billion(44)")},
{"+86",new CountryData(" *** *** *** ***",0,"China","CN/CHN","86","1,338,612,968(1)","9,596,961(5)","7.973Trillion(2)")},
{"+61x",new CountryData(" *** *** *** ***",0,"ChristmasIsland","CX/CXR","61","1,402(231)","135(221)","0(228)")},
{"+57",new CountryData(" *** *** *** ***",0,"Colombia","CO/COL","57","45,644,023(28)","1,138,914(27)","395.4Billion(28)")},
{"+269",new CountryData(" *** *** *** ***",0,"Comoros","KM/COM","269","752,438(161)","2,235(180)","751.2Million(207)")},
{"+682",new CountryData(" *** *** *** ***",0,"CookIslands","CK/COK","682","11,870(222)","236(214)","183.2Million(215)")},
{"+506",new CountryData(" *** *** *** ***",0,"CostaRica","CR/CRC","506","4,253,877(123)","51,100(130)","48.32Billion(88)")},
{"+385",new CountryData(" *** *** *** ***",0,"Croatia","HR/HRV","385","4,489,409(121)","56,594(127)","82.39Billion(72)")},
{"+53",new CountryData(" *** *** *** ***",0,"Cuba","CU/CUB","53","11,451,652(72)","110,860(106)","108.2Billion(63)")},
{"+357",new CountryData(" *** *** *** ***",0,"Cyprus","CY/CYP","357","796,740(159)","9,251(171)","22.7Billion(113)")},
{"+420",new CountryData(" *** *** *** ***",9,"CzechRepublic","CZ/CZE","420","10,211,904(80)","78,867(116)","265.2Billion(42)")},
{"+243",new CountryData(" *** *** *** ***",0,"DemocraticRepublicoftheCongo","CD/COD","243","68,692,542(18)","2,344,858(13)","20.64Billion(120)")},
{"+45",new CountryData(" *** *** *** ***",0,"Denmark","DK/DNK","45","5,500,510(110)","43,094(134)","203.6Billion(50)")},
{"+253",new CountryData(" *** *** *** ***",0,"Djibouti","DJ/DJI","253","516,055(168)","23,200(151)","1.885Billion(183)")},
{"+1767",new CountryData(" *** *** *** ***",0,"Dominica","DM/DMA","1767","72,660(202)","751(189)","719.6Million(208)")},
{"+1809",new CountryData(" *** *** *** ***",0,"DominicanRepublic","DO/DOM","1809","9,650,054(85)","48,670(132)","78Billion(75)")},
{"+593",new CountryData(" *** *** *** ***",0,"Ecuador","EC/ECU","593","14,573,101(64)","283,561(74)","107.7Billion(64)")},
{"+20",new CountryData(" *** *** *** ***",0,"Egypt","EG/EGY","20","83,082,869(15)","1,001,450(31)","443.7Billion(26)")},
{"+503",new CountryData(" *** *** *** ***",0,"ElSalvador","SV/SLV","503","7,185,218(99)","21,041(154)","43.63Billion(90)")},
{"+240",new CountryData(" *** *** *** ***",0,"EquatorialGuinea","GQ/GNQ","240","633,441(165)","28,051(146)","22.95Billion(112)")},
{"+291",new CountryData(" *** *** *** ***",0,"Eritrea","ER/ERI","291","5,647,168(109)","117,600(101)","3.945Billion(165)")},
{"+372",new CountryData(" *** *** *** ***",0,"Estonia","EE/EST","372","1,299,371(152)","45,228(133)","27.41Billion(109)")},
{"+251",new CountryData(" *** *** *** ***",0,"Ethiopia","ET/ETH","251","85,237,338(14)","1,104,300(28)","68.77Billion(79)")},
{"+500",new CountryData(" *** *** *** ***",0,"FalklandIslands","FK/FLK","500","3,140(227)","12,173(165)","105.1Million(219)")},
{"+298",new CountryData(" *** *** *** ***",0,"FaroeIslands","FO/FRO","298","48,856(208)","1,393(183)","1000Million(198)")},
{"+679",new CountryData(" *** *** *** ***",0,"Fiji","FJ/FJI","679","944,720(157)","18,274(157)","3.579Billion(167)")},
{"+358",new CountryData(" *** *** *** ***",0,"Finland","FI/FIN","358","5,250,275(113)","338,145(65)","193.5Billion(53)")},
{"+33",new CountryData(" *** *** *** ***",0,"France","FR/FRA","33","64,057,792(21)","643,427(43)","2.128Trillion(8)")},
{"+689",new CountryData(" *** *** *** ***",0,"FrenchPolynesia","PF/PYF","689","287,032(179)","4,167(175)","4.718Billion(160)")},
{"+241",new CountryData(" *** *** *** ***",0,"Gabon","GA/GAB","241","1,514,993(151)","267,667(77)","21.11Billion(118)")},
{"+220",new CountryData(" *** *** *** ***",0,"Gambia","GM/GMB","220","1,782,893(148)","11,295(167)","2.272Billion(179)")},
{"+970",new CountryData(" *** *** *** ***",0,"GazaStrip","/","970","1,551,859(149)","360(205)","11.95Billion(141)")},
{"+995",new CountryData(" *** *** *** ***",0,"Georgia","GE/GEO","995","4,615,807(118)","69,700(121)","21.51Billion(117)")},
{"+49",new CountryData(" *** *** *** ***",0,"Germany","DE/DEU","49","82,329,758(16)","357,022(63)","2.918Trillion(5)")},
{"+233",new CountryData(" *** *** *** ***",0,"Ghana","GH/GHA","233","23,832,495(47)","238,533(82)","34.2Billion(99)")},
{"+350",new CountryData(" *** *** *** ***",0,"Gibraltar","GI/GIB","350","28,034(214)","7(235)","1.066Billion(196)")},
{"+30",new CountryData(" *** *** *** ***",0,"Greece","GR/GRC","30","10,737,428(74)","131,957(97)","343Billion(33)")},
{"+299",new CountryData(" *** *** *** ***",0,"Greenland","GL/GRL","299","57,600(206)","2,166,086(14)","1.1Billion(193)")},
{"+1473",new CountryData(" *** *** *** ***",0,"Grenada","GD/GRD","1473","90,739(196)","344(206)","1.161Billion(192)")},
{"+1671",new CountryData(" *** *** *** ***",0,"Guam","GU/GUM","1671","160,595(187)","544(196)","2.5Billion(178)")},
{"+502",new CountryData(" *** *** *** ***",0,"Guatemala","GT/GTM","502","13,276,517(68)","108,889(107)","68.58Billion(80)")},
{"+224",new CountryData(" *** *** *** ***",0,"Guinea","GN/GIN","224","10,057,975(81)","245,857(79)","10.6Billion(146)")},
{"+245",new CountryData(" *** *** *** ***",0,"Guinea-Bissau","GW/GNB","245","1,533,964(150)","36,125(138)","904.2Million(202)")},
{"+592",new CountryData(" *** *** *** ***",0,"Guyana","GY/GUY","592","772,298(160)","214,969(85)","2.966Billion(173)")},
{"+509",new CountryData(" *** *** *** ***",0,"Haiti","HT/HTI","509","9,035,536(88)","27,750(148)","11.5Billion(144)")},
{"+39x",new CountryData(" *** *** *** ***",0,"HolySee(VaticanCity)","VA/VAT","39","826(233)","0(238)","0(228)")},
{"+504",new CountryData(" *** *** *** ***",0,"Honduras","HN/HND","504","7,792,854(93)","112,090(103)","33.72Billion(101)")},
{"+852",new CountryData(" *** *** *** ***",0,"HongKong","HK/HKG","852","7,055,071(100)","1,104(184)","306.6Billion(39)")},
{"+36",new CountryData(" *** *** *** ***",0,"Hungary","HU/HUN","36","9,905,596(82)","93,028(110)","196.6Billion(52)")},
{"+354",new CountryData(" *** *** *** ***",0,"Iceland","IS/IS","354","306,694(178)","103,000(108)","12.71Billion(139)")},
{"+91",new CountryData(" *** *** *** ***",0,"India","IN/IND","91","1,166,079,217(2)","3,287,263(8)","3.297Trillion(4)")},
{"+62",new CountryData(" *** *** *** ***",0,"Indonesia","ID/IDN","62","240,271,522(4)","1,904,569(17)","914.6Billion(15)")},
{"+98",new CountryData(" *** *** *** ***",0,"Iran","IR/IRN","98","66,429,284(19)","1,648,195(19)","841.7Billion(17)")},
{"+964",new CountryData(" *** *** *** ***",0,"Iraq","IQ/IRQ","964","28,945,657(40)","438,317(59)","103.9Billion(65)")},
{"+353",new CountryData(" *** *** *** ***",0,"Ireland","IE/IRL","353","4,203,200(125)","70,273(120)","188.4Billion(54)")},
{"+44i",new CountryData(" *** *** *** ***",0,"IsleofMan","IM/IMN","44","76,512(201)","572(195)","2.719Billion(175)")},
{"+972",new CountryData(" *** *** *** ***",0,"Israel","IL/ISR","972","7,233,701(97)","22,072(153)","201.4Billion(51)")},
{"+39",new CountryData(" *** *** *** ***",0,"Italy","IT/ITA","39","58,126,212(23)","301,340(72)","1.823Trillion(10)")},
{"+225",new CountryData(" *** *** *** ***",0,"IvoryCoast","CI/CIV","225","20,617,068(56)","322,463(69)","33.85Billion(100)")},
{"+1876",new CountryData(" *** *** *** ***",0,"Jamaica","JM/JAM","1876","2,825,928(138)","10,991(168)","20.91Billion(119)")},
{"+81",new CountryData(" *** *** *** ***",0,"Japan","JP/JPN","81","127,078,679(10)","377,915(62)","4.329Trillion(3)")},
{"+962",new CountryData(" *** *** *** ***",0,"Jordan","JO/JOR","962","6,342,948(104)","89,342(112)","31.61Billion(102)")},
{"+7k",new CountryData(" *** *** *** ***",0,"Kazakhstan","KZ/KAZ","7","15,399,437(62)","2,724,900(10)","175.8Billion(56)")},
{"+254",new CountryData(" *** *** *** ***",0,"Kenya","KE/KEN","254","39,002,772(33)","580,367(49)","61.51Billion(83)")},
{"+686",new CountryData(" *** *** *** ***",0,"Kiribati","KI/KIR","686","112,850(190)","811(187)","579.5Million(209)")},
{"+381",new CountryData(" *** *** *** ***",0,"Kosovo","/","381","1,804,838(147)","10,887(169)","5Billion(159)")},
{"+965",new CountryData(" *** *** *** ***",0,"Kuwait","KW/KWT","965","2,691,158(139)","17,818(158)","149.1Billion(57)")},
{"+996",new CountryData(" *** *** *** ***",0,"Kyrgyzstan","KG/KGZ","996","5,431,747(112)","199,951(87)","11.61Billion(143)")},
{"+856",new CountryData(" *** *** *** ***",0,"Laos","LA/LAO","856","6,834,942(102)","236,800(84)","13.98Billion(134)")},
{"+371",new CountryData(" *** *** *** ***",0,"Latvia","LV/LVA","371","2,231,503(141)","64,589(124)","38.86Billion(97)")},
{"+961",new CountryData(" *** *** *** ***",0,"Lebanon","LB/LBN","961","4,017,095(126)","10,400(170)","44.06Billion(89)")},
{"+266",new CountryData(" *** *** *** ***",0,"Lesotho","LS/LSO","266","2,130,819(142)","30,355(142)","3.293Billion(169)")},
{"+231",new CountryData(" *** *** *** ***",0,"Liberia","LR/LBR","231","3,441,790(132)","111,369(104)","1.526Billion(191)")},
{"+218",new CountryData(" *** *** *** ***",0,"Libya","LY/LBY","218","6,310,434(105)","1,759,540(18)","88.83Billion(70)")},
{"+423",new CountryData(" *** *** *** ***",0,"Liechtenstein","LI/LIE","423","34,761(210)","160(218)","4.16Billion(164)")},
{"+370",new CountryData(" *** *** *** ***",0,"Lithuania","LT/LTU","370","3,555,179(130)","65,300(123)","63.33Billion(82)")},
{"+352",new CountryData(" *** *** *** ***",0,"Luxembourg","LU/LUX","352","491,775(169)","2,586(179)","39.37Billion(96)")},
{"+853",new CountryData(" *** *** *** ***",0,"Macau","MO/MAC","853","559,846(167)","28(230)","18.14Billion(126)")},
{"+389",new CountryData(" *** *** *** ***",0,"Macedonia","MK/MKD","389","2,066,718(144)","25,713(150)","18.78Billion(124)")},
{"+261",new CountryData(" *** *** *** ***",0,"Madagascar","MG/MDG","261","20,653,556(55)","587,041(47)","20.13Billion(122)")},
{"+265",new CountryData(" *** *** *** ***",0,"Malawi","MW/MWI","265","14,268,711(66)","118,484(100)","11.81Billion(142)")},
{"+60",new CountryData(" *** *** *** ***",0,"Malaysia","MY/MYS","60","25,715,819(46)","329,847(67)","384.3Billion(30)")},
{"+960",new CountryData(" *** *** *** ***",0,"Maldives","MV/MDV","960","396,334(174)","298(209)","1.716Billion(185)")},
{"+223",new CountryData(" *** *** *** ***",0,"Mali","ML/MLI","223","12,666,987(70)","1,240,192(25)","14.59Billion(133)")},
{"+356",new CountryData(" *** *** *** ***",0,"Malta","MT/MLT","356","405,165(173)","316(207)","9.962Billion(148)")},
{"+692",new CountryData(" *** *** *** ***",0,"MarshallIslands","MH/MHL","692","64,522(205)","181(216)","133.5Million(217)")},
{"+222",new CountryData(" *** *** *** ***",0,"Mauritania","MR/MRT","222","3,129,486(135)","1,030,700(30)","6.308Billion(153)")},
{"+230",new CountryData(" *** *** *** ***",0,"Mauritius","MU/MUS","230","1,284,264(153)","2,040(181)","15.27Billion(132)")},
{"+262",new CountryData(" *** *** *** ***",0,"Mayotte","YT/MYT","262","223,765(183)","374(204)","953.6Million(201)")},
{"+52",new CountryData(" *** *** *** ***",0,"Mexico","MX/MEX","52","111,211,789(11)","1,964,375(16)","1.563Trillion(11)")},
{"+691",new CountryData(" *** *** *** ***",0,"Micronesia","FM/FSM","691","107,434(192)","702(192)","238.1Million(213)")},
{"+373",new CountryData(" *** *** *** ***",0,"Moldova","MD/MDA","373","4,320,748(122)","33,851(140)","10.67Billion(145)")},
{"+377",new CountryData(" *** *** *** ***",0,"Monaco","MC/MCO","377","32,965(211)","2(237)","976.3Million(200)")},
{"+976",new CountryData(" *** *** *** ***",0,"Mongolia","MN/MNG","976","3,041,142(136)","1,564,116(20)","9.476Billion(150)")},
{"+382",new CountryData(" *** *** *** ***",0,"Montenegro","ME/MNE","382","672,180(164)","13,812(162)","6.816Billion(152)")},
{"+1664",new CountryData(" *** *** *** ***",0,"Montserrat","MS/MSR","1664","5,097(226)","102(223)","29Million(223)")},
{"+212",new CountryData(" *** *** *** ***",0,"Morocco","MA/MAR","212","34,859,364(35)","446,550(58)","136.6Billion(58)")},
{"+258",new CountryData(" *** *** *** ***",0,"Mozambique","MZ/MOZ","258","21,669,278(52)","799,380(36)","18.94Billion(123)")},
{"+264",new CountryData(" *** *** *** ***",0,"Namibia","NA/NAM","264","2,108,665(143)","824,292(35)","13.25Billion(135)")},
{"+674",new CountryData(" *** *** *** ***",0,"Nauru","NR/NRU","674","14,019(220)","21(232)","60Million(221)")},
{"+977",new CountryData(" *** *** *** ***",0,"Nepal","NP/NPL","977","28,563,377(42)","147,181(94)","31.08Billion(103)")},
{"+31",new CountryData(" *** *** *** ***",0,"Netherlands","NL/NLD","31","16,715,999(59)","41,543(135)","672Billion(20)")},
{"+599",new CountryData(" *** *** *** ***",0,"NetherlandsAntilles","AN/ANT","599","227,049(182)","800(188)","2.8Billion(174)")},
{"+687",new CountryData(" *** *** *** ***",0,"NewCaledonia","NC/NCL","687","227,436(181)","18,575(156)","3.158Billion(171)")},
{"+64",new CountryData(" *** *** *** ***",0,"NewZealand","NZ/NZL","64","4,213,418(124)","267,710(76)","116.7Billion(60)")},
{"+505",new CountryData(" *** *** *** ***",0,"Nicaragua","NI/NIC","505","5,891,199(108)","130,370(98)","16.79Billion(129)")},
{"+227",new CountryData(" *** *** *** ***",0,"Niger","NE/NER","227","15,306,252(63)","1,267,000(23)","10.04Billion(147)")},
{"+234",new CountryData(" *** *** *** ***",0,"Nigeria","NG/NGA","234","149,229,090(8)","923,768(33)","335.4Billion(35)")},
{"+683",new CountryData(" *** *** *** ***",0,"Niue","NU/NIU","683","1,398(232)","260(212)","10.01Million(226)")},
{"+672x",new CountryData(" *** *** *** ***",0,"NorfolkIsland","/NFK","672","2,141(228)","36(229)","0(228)")},
{"+850",new CountryData(" *** *** *** ***",0,"NorthKorea","KP/PRK","850","22,665,345(50)","120,538(99)","40Billion(94)")},
{"+1670",new CountryData(" *** *** *** ***",0,"NorthernMarianaIslands","MP/MNP","1670","88,662(197)","464(198)","900Million(204)")},
{"+47",new CountryData(" *** *** *** ***",0,"Norway","NO/NOR","47","4,660,539(116)","323,802(68)","275.4Billion(40)")},
{"+968",new CountryData(" *** *** *** ***",0,"Oman","OM/OMN","968","3,418,085(133)","309,500(71)","66.98Billion(81)")},
{"+92",new CountryData(" *** *** *** ***",0,"Pakistan","PK/PAK","92","176,242,949(6)","796,095(37)","427.3Billion(27)")},
{"+680",new CountryData(" *** *** *** ***",0,"Palau","PW/PLW","680","20,796(217)","459(199)","164Million(216)")},
{"+507",new CountryData(" *** *** *** ***",0,"Panama","PA/PAN","507","3,360,474(134)","75,420(118)","38.83Billion(98)")},
{"+675",new CountryData(" *** *** *** ***",0,"PapuaNewGuinea","PG/PNG","675","6,057,263(106)","462,840(55)","13.21Billion(136)")},
{"+595",new CountryData(" *** *** *** ***",0,"Paraguay","PY/PRY","595","6,995,655(101)","406,752(60)","28.89Billion(107)")},
{"+51",new CountryData(" *** *** *** ***",0,"Peru","PE/PER","51","29,546,963(39)","1,285,216(21)","247.3Billion(43)")},
{"+63",new CountryData(" *** *** *** ***",0,"Philippines","PH/PHL","63","97,976,603(12)","300,000(73)","317.5Billion(37)")},
{"+870",new CountryData(" *** *** *** ***",0,"PitcairnIslands","PN/PCN","870","48(235)","47(228)","0(228)")},
{"+48",new CountryData(" *** *** *** ***",0,"Poland","PL/POL","48","38,482,919(34)","312,685(70)","667.9Billion(21)")},
{"+351",new CountryData(" *** *** *** ***",0,"Portugal","PT/PRT","351","10,707,924(75)","92,090(111)","236.5Billion(47)")},
{"+1x",new CountryData(" *** *** *** ***",0,"PuertoRico","PR/PRI","1","3,971,020(128)","13,790(163)","70.23Billion(78)")},
{"+974",new CountryData(" *** *** *** ***",0,"Qatar","QA/QAT","974","833,285(158)","11,586(166)","91.33Billion(69)")},
{"+242",new CountryData(" *** *** *** ***",0,"RepublicoftheCongo","CG/COG","242","4,012,809(127)","342,000(64)","15.35Billion(131)")},
{"+40",new CountryData(" *** *** *** ***",0,"Romania","RO/ROU","40","22,215,421(51)","238,391(83)","271.4Billion(41)")},
{"+7",new CountryData(" *** *** *** ***",0,"Russia","RU/RUS","7","140,041,247(9)","17,098,242(1)","2.266Trillion(6)")},
{"+250",new CountryData(" *** *** *** ***",0,"Rwanda","RW/RWA","250","10,473,282(77)","26,338(149)","9.706Billion(149)")},
{"+590",new CountryData(" *** *** *** ***",0,"SaintBarthelemy","BL/BLM","590","7,448(224)","0(238)","0(228)")},
{"+290",new CountryData(" *** *** *** ***",0,"SaintHelena","SH/SHN","290","7,637(223)","308(208)","18Million(224)")},
{"+1869",new CountryData(" *** *** *** ***",0,"SaintKittsandNevis","KN/KNA","1869","40,131(209)","261(211)","777.7Million(206)")},
{"+1758",new CountryData(" *** *** *** ***",0,"SaintLucia","LC/LCA","1758","160,267(188)","616(194)","1.778Billion(184)")},
{"+1599",new CountryData(" *** *** *** ***",0,"SaintMartin","MF/MAF","1599","29,820(213)","54(227)","0(228)")},
{"+508",new CountryData(" *** *** *** ***",0,"SaintPierreandMiquelon","PM/SPM","508","7,051(225)","242(213)","48.3Million(222)")},
{"+1784",new CountryData(" *** *** *** ***",0,"SaintVincentandtheGrenadines","VC/VCT","1784","104,574(193)","389(203)","1.07Billion(195)")},
{"+685",new CountryData(" *** *** *** ***",0,"Samoa","WS/WSM","685","219,998(184)","2,831(178)","1.049Billion(197)")},
{"+378",new CountryData(" *** *** *** ***",0,"SanMarino","SM/SMR","378","30,324(212)","61(225)","1.662Billion(187)")},
{"+239",new CountryData(" *** *** *** ***",0,"SaoTomeandPrincipe","ST/STP","239","212,679(186)","964(185)","276.5Million(212)")},
{"+966",new CountryData(" *** *** *** ***",0,"SaudiArabia","SA/SAU","966","28,686,633(41)","2,149,690(15)","576.5Billion(22)")},
{"+221",new CountryData(" *** *** *** ***",0,"Senegal","SN/SEN","221","13,711,597(67)","196,722(88)","21.98Billion(115)")},
{"+381s",new CountryData(" *** *** *** ***",0,"Serbia","RS/SRB","381","7,379,339(95)","77,474(117)","80.34Billion(74)")},
{"+248",new CountryData(" *** *** *** ***",0,"Seychelles","SC/SYC","248","87,476(198)","455(200)","1.715Billion(186)")},
{"+232",new CountryData(" *** *** *** ***",0,"SierraLeone","SL/SLE","232","6,440,053(103)","71,740(119)","4.285Billion(162)")},
{"+65",new CountryData(" *** *** *** ***",0,"Singapore","SG/SGP","65","4,657,542(117)","697(193)","237.3Billion(46)")},
{"+421",new CountryData(" *** *** *** ***",0,"Slovakia","SK/SVK","421","5,463,046(111)","49,035(131)","119.5Billion(59)")},
{"+386",new CountryData(" *** *** *** ***",0,"Slovenia","SI/SVN","386","2,005,692(145)","20,273(155)","59.34Billion(84)")},
{"+677",new CountryData(" *** *** *** ***",0,"SolomonIslands","SB/SLB","677","595,613(166)","28,896(144)","1.078Billion(194)")},
{"+252",new CountryData(" *** *** *** ***",0,"Somalia","SO/SOM","252","9,832,017(83)","637,657(44)","5.524Billion(155)")},
{"+27",new CountryData(" *** *** *** ***",0,"SouthAfrica","ZA/ZAF","27","49,052,489(24)","1,219,090(26)","491Billion(25)")},
{"+82",new CountryData(" *** *** *** ***",0,"SouthKorea","KR/KOR","82","48,508,972(25)","99,720(109)","1.335Trillion(13)")},
{"+34",new CountryData(" *** *** *** ***",0,"Spain","ES/ESP","34","40,525,002(32)","505,370(52)","1.403Trillion(12)")},
{"+94",new CountryData(" *** *** *** ***",0,"SriLanka","LK/LKA","94","21,324,791(53)","65,610(122)","91.87Billion(68)")},
{"+249",new CountryData(" *** *** *** ***",0,"Sudan","SD/SDN","249","41,087,825(29)","2,505,813(11)","88.08Billion(71)")},
{"+597",new CountryData(" *** *** *** ***",0,"Suriname","SR/SUR","597","481,267(170)","163,820(92)","4.254Billion(163)")},
{"+s",new CountryData(" *** *** *** ***",0,"Svalbard","SJ/SJM","","2,116(229)","62,045(125)","0(228)")},
{"+268",new CountryData(" *** *** *** ***",0,"Swaziland","SZ/SWZ","268","1,123,913(156)","17,364(159)","5.702Billion(154)")},
{"+46",new CountryData(" *** *** *** ***",0,"Sweden","SE/SWE","46","9,059,651(87)","450,295(56)","344.3Billion(32)")},
{"+41",new CountryData(" *** *** *** ***",0,"Switzerland","CH/CHE","41","7,604,467(94)","41,277(136)","316.7Billion(38)")},
{"+963",new CountryData(" *** *** *** ***",0,"Syria","SY/SYR","963","20,178,485(57)","185,180(89)","98.83Billion(66)")},
{"+886",new CountryData(" *** *** *** ***",0,"Taiwan","TW/TWN","886","22,974,347(49)","35,980(139)","712Billion(19)")},
{"+992",new CountryData(" *** *** *** ***",0,"Tajikistan","TJ/TJK","992","7,349,145(96)","143,100(96)","13.16Billion(137)")},
{"+255",new CountryData(" *** *** *** ***",0,"Tanzania","TZ/TZA","255","41,048,532(30)","947,300(32)","54.25Billion(87)")},
{"+66",new CountryData(" *** *** *** ***",0,"Thailand","TH/THA","66","65,905,410(20)","513,120(51)","547.4Billion(24)")},
{"+670",new CountryData(" *** *** *** ***",0,"Timor-Leste","TL/TLS","670","1,131,612(155)","14,874(160)","2.52Billion(177)")},
{"+228",new CountryData(" *** *** *** ***",0,"Togo","TG/TGO","228","6,019,877(107)","56,785(126)","5.118Billion(157)")},
{"+690",new CountryData(" *** *** *** ***",0,"Tokelau","TK/TKL","690","1,416(230)","12(234)","1.5Million(227)")},
{"+676",new CountryData(" *** *** *** ***",0,"Tonga","TO/TON","676","120,898(189)","747(190)","549Million(211)")},
{"+1868",new CountryData(" *** *** *** ***",0,"TrinidadandTobago","TT/TTO","1868","1,229,953(154)","5,128(174)","29.01Billion(106)")},
{"+216",new CountryData(" *** *** *** ***",0,"Tunisia","TN/TUN","216","10,486,339(76)","163,610(93)","81.71Billion(73)")},
{"+90",new CountryData(" *** *** *** ***",0,"Turkey","TR/TUR","90","76,805,524(17)","783,562(38)","902.7Billion(16)")},
{"+993",new CountryData(" *** *** *** ***",0,"Turkmenistan","TM/TKM","993","4,884,887(114)","488,100(53)","29.78Billion(104)")},
{"+1649",new CountryData(" *** *** *** ***",0,"TurksandCaicosIslands","TC/TCA","1649","22,942(216)","948(186)","216Million(214)")},
{"+688",new CountryData(" *** *** *** ***",0,"Tuvalu","TV/TUV","688","12,373(221)","26(231)","14.94Million(225)")},
{"+256",new CountryData(" *** *** *** ***",0,"Uganda","UG/UGA","256","32,369,558(38)","241,038(81)","39.38Billion(95)")},
{"+380",new CountryData(" *** *** *** ***",0,"Ukraine","UA/UKR","380","45,700,395(27)","603,550(46)","339.8Billion(34)")},
{"+971",new CountryData(" *** *** *** ***",0,"UnitedArabEmirates","AE/ARE","971","4,798,491(115)","83,600(115)","184.3Billion(55)")},
{"+44",new CountryData(" *** *** *** ***",0,"UnitedKingdom","GB/GBR","44","61,113,205(22)","243,610(80)","2.226Trillion(7)")},
{"+1",new CountryData("-***-****-***",0,"UnitedStates","US/USA","1","307,212,123(3)","9,826,675(4)","14.26Trillion(1)")},
{"+598",new CountryData(" *** *** *** ***",0,"Uruguay","UY/URY","598","3,494,382(131)","176,215(91)","43.16Billion(92)")},
{"+1340",new CountryData(" *** *** *** ***",0,"USVirginIslands","VI/VIR","1340","109,825(191)","1,910(182)","1.577Billion(190)")},
{"+998",new CountryData(" *** *** *** ***",0,"Uzbekistan","UZ/UZB","998","27,606,007(44)","447,400(57)","71.67Billion(77)")},
{"+678",new CountryData(" *** *** *** ***",0,"Vanuatu","VU/VUT","678","218,519(185)","12,189(164)","988.5Million(199)")},
{"+58",new CountryData(" *** *** *** ***",0,"Venezuela","VE/VEN","58","26,814,843(45)","912,050(34)","357.4Billion(31)")},
{"+84",new CountryData(" *** *** *** ***",0,"Vietnam","VN/VNM","84","86,967,524(13)","331,210(66)","241.7Billion(45)")},
{"+681",new CountryData(" *** *** *** ***",0,"WallisandFutuna","WF/WLF","681","15,289(218)","142(220)","60Million(220)")},
{"+970w",new CountryData(" *** *** *** ***",0,"WestBank","/","970","2,461,267(140)","5,860(172)","11.95Billion(140)")},
{"+967",new CountryData(" *** *** *** ***",0,"Yemen","YE/YEM","967","23,822,783(48)","527,968(50)","55.28Billion(85)")},
{"+260",new CountryData(" *** *** *** ***",0,"Zambia","ZM/ZMB","260","11,862,740(71)","752,618(40)","17.5Billion(128)")},
{"+263",new CountryData(" *** *** *** ***",0,"Zimbabwe","ZW/ZWE","263","11,392,629(73)","390,757(61)","1.925Billion(182)")},
};
}
}
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

15:55:47 01.01.2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Hamon
{
/// <summary>
/// Kdyz uz, tak poradne
/// </summary>
class Program
{
static void Main(string[] args)
{
string[] num = new string[] { "+420 123 456 789", "+352123 456789", "123456789", "12345", "+420123 456789 1234567" };
foreach (string s in num)
Console.WriteLine(CountryData.Hamoun(s));
}
public class CountryData
{
string z_country;
public CountryData(string country, string abbrev, string code, string popul, string area, string gdp)
{
z_country = country;
}
public static string Hamoun(string unformatted)
{
var num = Regex.Replace(unformatted, @"[^+^0-9]+", "");
var code = "+420";
foreach (var c in data.Keys)
{
if (unformatted.StartsWith(c))
{
num = num.Replace(c, "");
code = c;
break;
}
}
return code + " " + Regex.Replace(num.PadLeft(9,'0'), @"(\d{3})(\d{3})(\d{3})", "$1 $2 $3") +": "+ data[code].z_country;
}
static Dictionary<string, CountryData> data = new Dictionary<string, CountryData>{
{"+93",new CountryData("Afghanistan","AF/AFG","93","28,396,000(43)","652,230(42)","22.27Billion(114)")},
{"+355",new CountryData("Albania","AL/ALB","355","3,639,453(129)","28,748(145)","21.81Billion(116)")},
{"+213",new CountryData("Algeria","DZ/DZA","213","34,178,188(36)","2,381,741(12)","232.9Billion(48)")},
{"+1684",new CountryData("AmericanSamoa","AS/ASM","1684","65,628(204)","199(215)","575.3Million(210)")},
{"+376",new CountryData("Andorra","AD/AND","376","83,888(200)","468(197)","3.66Billion(166)")},
{"+244",new CountryData("Angola","AO/AGO","244","12,799,293(69)","1,246,700(24)","110.3Billion(62)")},
{"+1264",new CountryData("Anguilla","AI/AIA","1264","14,436(219)","91(224)","108.9Million(218)")},
{"+672",new CountryData("Antarctica","AQ/ATA","672","0(236)","14,000,000(2)","0(228)")},
{"+1268",new CountryData("AntiguaandBarbuda","AG/ATG","1268","85,632(199)","443(201)","1.657Billion(188)")},
{"+54",new CountryData("Argentina","AR/ARG","54","40,913,584(31)","2,780,400(9)","573.9Billion(23)")},
{"+374",new CountryData("Armenia","AM/ARM","374","2,967,004(137)","29,743(143)","18.77Billion(125)")},
{"+297",new CountryData("Aruba","AW/ABW","297","103,065(194)","180(217)","2.258Billion(180)")},
{"+61",new CountryData("Australia","AU/AUS","61","21,262,641(54)","7,741,220(7)","800.2Billion(18)")},
{"+43",new CountryData("Austria","AT/AUT","43","8,210,281(92)","83,871(114)","329.5Billion(36)")},
{"+994",new CountryData("Azerbaijan","AZ/AZE","994","8,238,672(91)","86,600(113)","77.61Billion(76)")},
{"+1242",new CountryData("Bahamas","BS/BHS","1242","309,156(176)","13,880(161)","9.093Billion(151)")},
{"+973",new CountryData("Bahrain","BH/BHR","973","727,785(162)","741(191)","26.82Billion(111)")},
{"+880",new CountryData("Bangladesh","BD/BGD","880","156,050,883(7)","143,998(95)","224Billion(49)")},
{"+1246",new CountryData("Barbados","BB/BRB","1246","284,589(180)","430(202)","5.425Billion(156)")},
{"+375",new CountryData("Belarus","BY/BLR","375","9,648,533(86)","207,600(86)","114.1Billion(61)")},
{"+32",new CountryData("Belgium","BE/BEL","32","10,414,336(78)","30,528(141)","389.3Billion(29)")},
{"+501",new CountryData("Belize","BZ/BLZ","501","307,899(177)","22,966(152)","2.536Billion(176)")},
{"+229",new CountryData("Benin","BJ/BEN","229","8,791,832(90)","112,622(102)","12.83Billion(138)")},
{"+1441",new CountryData("Bermuda","BM/BMU","1441","67,837(203)","54(226)","4.5Billion(161)")},
{"+975",new CountryData("Bhutan","BT/BTN","975","691,141(163)","38,394(137)","3.524Billion(168)")},
{"+591",new CountryData("Bolivia","BO/BOL","591","9,775,246(84)","1,098,581(29)","43.27Billion(91)")},
{"+387",new CountryData("BosniaandHerzegovina","BA/BIH","387","4,613,414(119)","51,197(129)","29.7Billion(105)")},
{"+267",new CountryData("Botswana","BW/BWA","267","1,990,876(146)","581,730(48)","27.06Billion(110)")},
{"+55",new CountryData("Brazil","BR/BRA","55","198,739,269(5)","8,514,877(6)","1.993Trillion(9)")},
{"+1284",new CountryData("BritishVirginIslands","VG/VGB","1284","24,491(215)","151(219)","853.4Million(205)")},
{"+673",new CountryData("Brunei","BN/BRN","673","388,190(175)","5,765(173)","20.25Billion(121)")},
{"+359",new CountryData("Bulgaria","BG/BGR","359","7,204,687(98)","110,879(105)","93.75Billion(67)")},
{"+226",new CountryData("BurkinaFaso","BF/BFA","226","15,746,232(61)","274,200(75)","17.82Billion(127)")},
{"+95",new CountryData("Burma(Myanmar)","MM/MMR","95","48,137,741(26)","676,578(41)","55.13Billion(86)")},
{"+257",new CountryData("Burundi","BI/BDI","257","8,988,091(89)","27,830(147)","3.102Billion(172)")},
{"+855",new CountryData("Cambodia","KH/KHM","855","14,494,293(65)","181,035(90)","27.94Billion(108)")},
{"+237",new CountryData("Cameroon","CM/CMR","237","18,879,301(58)","475,440(54)","42.75Billion(93)")},
{"+1c",new CountryData("Canada","CA/CAN","1","33,487,208(37)","9,984,670(3)","1.3Trillion(14)")},
{"+238",new CountryData("CapeVerde","CV/CPV","238","429,474(171)","4,033(176)","1.626Billion(189)")},
{"+1345",new CountryData("CaymanIslands","KY/CYM","1345","49,035(207)","264(210)","1.939Billion(181)")},
{"+236",new CountryData("CentralAfricanRepublic","CF/CAF","236","4,511,488(120)","622,984(45)","3.198Billion(170)")},
{"+235",new CountryData("Chad","TD/TCD","235","10,329,208(79)","1,284,000(22)","15.86Billion(130)")},
{"+56",new CountryData("Chile","CL/CHL","56","16,601,707(60)","756,102(39)","244.5Billion(44)")},
{"+86",new CountryData("China","CN/CHN","86","1,338,612,968(1)","9,596,961(5)","7.973Trillion(2)")},
{"+61x",new CountryData("ChristmasIsland","CX/CXR","61","1,402(231)","135(221)","0(228)")},
{"+57",new CountryData("Colombia","CO/COL","57","45,644,023(28)","1,138,914(27)","395.4Billion(28)")},
{"+269",new CountryData("Comoros","KM/COM","269","752,438(161)","2,235(180)","751.2Million(207)")},
{"+682",new CountryData("CookIslands","CK/COK","682","11,870(222)","236(214)","183.2Million(215)")},
{"+506",new CountryData("CostaRica","CR/CRC","506","4,253,877(123)","51,100(130)","48.32Billion(88)")},
{"+385",new CountryData("Croatia","HR/HRV","385","4,489,409(121)","56,594(127)","82.39Billion(72)")},
{"+53",new CountryData("Cuba","CU/CUB","53","11,451,652(72)","110,860(106)","108.2Billion(63)")},
{"+357",new CountryData("Cyprus","CY/CYP","357","796,740(159)","9,251(171)","22.7Billion(113)")},
{"+420",new CountryData("CzechRepublic","CZ/CZE","420","10,211,904(80)","78,867(116)","265.2Billion(42)")},
{"+243",new CountryData("DemocraticRepublicoftheCongo","CD/COD","243","68,692,542(18)","2,344,858(13)","20.64Billion(120)")},
{"+45",new CountryData("Denmark","DK/DNK","45","5,500,510(110)","43,094(134)","203.6Billion(50)")},
{"+253",new CountryData("Djibouti","DJ/DJI","253","516,055(168)","23,200(151)","1.885Billion(183)")},
{"+1767",new CountryData("Dominica","DM/DMA","1767","72,660(202)","751(189)","719.6Million(208)")},
{"+1809",new CountryData("DominicanRepublic","DO/DOM","1809","9,650,054(85)","48,670(132)","78Billion(75)")},
{"+593",new CountryData("Ecuador","EC/ECU","593","14,573,101(64)","283,561(74)","107.7Billion(64)")},
{"+20",new CountryData("Egypt","EG/EGY","20","83,082,869(15)","1,001,450(31)","443.7Billion(26)")},
{"+503",new CountryData("ElSalvador","SV/SLV","503","7,185,218(99)","21,041(154)","43.63Billion(90)")},
{"+240",new CountryData("EquatorialGuinea","GQ/GNQ","240","633,441(165)","28,051(146)","22.95Billion(112)")},
{"+291",new CountryData("Eritrea","ER/ERI","291","5,647,168(109)","117,600(101)","3.945Billion(165)")},
{"+372",new CountryData("Estonia","EE/EST","372","1,299,371(152)","45,228(133)","27.41Billion(109)")},
{"+251",new CountryData("Ethiopia","ET/ETH","251","85,237,338(14)","1,104,300(28)","68.77Billion(79)")},
{"+500",new CountryData("FalklandIslands","FK/FLK","500","3,140(227)","12,173(165)","105.1Million(219)")},
{"+298",new CountryData("FaroeIslands","FO/FRO","298","48,856(208)","1,393(183)","1000Million(198)")},
{"+679",new CountryData("Fiji","FJ/FJI","679","944,720(157)","18,274(157)","3.579Billion(167)")},
{"+358",new CountryData("Finland","FI/FIN","358","5,250,275(113)","338,145(65)","193.5Billion(53)")},
{"+33",new CountryData("France","FR/FRA","33","64,057,792(21)","643,427(43)","2.128Trillion(8)")},
{"+689",new CountryData("FrenchPolynesia","PF/PYF","689","287,032(179)","4,167(175)","4.718Billion(160)")},
{"+241",new CountryData("Gabon","GA/GAB","241","1,514,993(151)","267,667(77)","21.11Billion(118)")},
{"+220",new CountryData("Gambia","GM/GMB","220","1,782,893(148)","11,295(167)","2.272Billion(179)")},
{"+970",new CountryData("GazaStrip","/","970","1,551,859(149)","360(205)","11.95Billion(141)")},
{"+995",new CountryData("Georgia","GE/GEO","995","4,615,807(118)","69,700(121)","21.51Billion(117)")},
{"+49",new CountryData("Germany","DE/DEU","49","82,329,758(16)","357,022(63)","2.918Trillion(5)")},
{"+233",new CountryData("Ghana","GH/GHA","233","23,832,495(47)","238,533(82)","34.2Billion(99)")},
{"+350",new CountryData("Gibraltar","GI/GIB","350","28,034(214)","7(235)","1.066Billion(196)")},
{"+30",new CountryData("Greece","GR/GRC","30","10,737,428(74)","131,957(97)","343Billion(33)")},
{"+299",new CountryData("Greenland","GL/GRL","299","57,600(206)","2,166,086(14)","1.1Billion(193)")},
{"+1473",new CountryData("Grenada","GD/GRD","1473","90,739(196)","344(206)","1.161Billion(192)")},
{"+1671",new CountryData("Guam","GU/GUM","1671","160,595(187)","544(196)","2.5Billion(178)")},
{"+502",new CountryData("Guatemala","GT/GTM","502","13,276,517(68)","108,889(107)","68.58Billion(80)")},
{"+224",new CountryData("Guinea","GN/GIN","224","10,057,975(81)","245,857(79)","10.6Billion(146)")},
{"+245",new CountryData("Guinea-Bissau","GW/GNB","245","1,533,964(150)","36,125(138)","904.2Million(202)")},
{"+592",new CountryData("Guyana","GY/GUY","592","772,298(160)","214,969(85)","2.966Billion(173)")},
{"+509",new CountryData("Haiti","HT/HTI","509","9,035,536(88)","27,750(148)","11.5Billion(144)")},
{"+39x",new CountryData("HolySee(VaticanCity)","VA/VAT","39","826(233)","0(238)","0(228)")},
{"+504",new CountryData("Honduras","HN/HND","504","7,792,854(93)","112,090(103)","33.72Billion(101)")},
{"+852",new CountryData("HongKong","HK/HKG","852","7,055,071(100)","1,104(184)","306.6Billion(39)")},
{"+36",new CountryData("Hungary","HU/HUN","36","9,905,596(82)","93,028(110)","196.6Billion(52)")},
{"+354",new CountryData("Iceland","IS/IS","354","306,694(178)","103,000(108)","12.71Billion(139)")},
{"+91",new CountryData("India","IN/IND","91","1,166,079,217(2)","3,287,263(8)","3.297Trillion(4)")},
{"+62",new CountryData("Indonesia","ID/IDN","62","240,271,522(4)","1,904,569(17)","914.6Billion(15)")},
{"+98",new CountryData("Iran","IR/IRN","98","66,429,284(19)","1,648,195(19)","841.7Billion(17)")},
{"+964",new CountryData("Iraq","IQ/IRQ","964","28,945,657(40)","438,317(59)","103.9Billion(65)")},
{"+353",new CountryData("Ireland","IE/IRL","353","4,203,200(125)","70,273(120)","188.4Billion(54)")},
{"+44i",new CountryData("IsleofMan","IM/IMN","44","76,512(201)","572(195)","2.719Billion(175)")},
{"+972",new CountryData("Israel","IL/ISR","972","7,233,701(97)","22,072(153)","201.4Billion(51)")},
{"+39",new CountryData("Italy","IT/ITA","39","58,126,212(23)","301,340(72)","1.823Trillion(10)")},
{"+225",new CountryData("IvoryCoast","CI/CIV","225","20,617,068(56)","322,463(69)","33.85Billion(100)")},
{"+1876",new CountryData("Jamaica","JM/JAM","1876","2,825,928(138)","10,991(168)","20.91Billion(119)")},
{"+81",new CountryData("Japan","JP/JPN","81","127,078,679(10)","377,915(62)","4.329Trillion(3)")},
{"+962",new CountryData("Jordan","JO/JOR","962","6,342,948(104)","89,342(112)","31.61Billion(102)")},
{"+7k",new CountryData("Kazakhstan","KZ/KAZ","7","15,399,437(62)","2,724,900(10)","175.8Billion(56)")},
{"+254",new CountryData("Kenya","KE/KEN","254","39,002,772(33)","580,367(49)","61.51Billion(83)")},
{"+686",new CountryData("Kiribati","KI/KIR","686","112,850(190)","811(187)","579.5Million(209)")},
{"+381",new CountryData("Kosovo","/","381","1,804,838(147)","10,887(169)","5Billion(159)")},
{"+965",new CountryData("Kuwait","KW/KWT","965","2,691,158(139)","17,818(158)","149.1Billion(57)")},
{"+996",new CountryData("Kyrgyzstan","KG/KGZ","996","5,431,747(112)","199,951(87)","11.61Billion(143)")},
{"+856",new CountryData("Laos","LA/LAO","856","6,834,942(102)","236,800(84)","13.98Billion(134)")},
{"+371",new CountryData("Latvia","LV/LVA","371","2,231,503(141)","64,589(124)","38.86Billion(97)")},
{"+961",new CountryData("Lebanon","LB/LBN","961","4,017,095(126)","10,400(170)","44.06Billion(89)")},
{"+266",new CountryData("Lesotho","LS/LSO","266","2,130,819(142)","30,355(142)","3.293Billion(169)")},
{"+231",new CountryData("Liberia","LR/LBR","231","3,441,790(132)","111,369(104)","1.526Billion(191)")},
{"+218",new CountryData("Libya","LY/LBY","218","6,310,434(105)","1,759,540(18)","88.83Billion(70)")},
{"+423",new CountryData("Liechtenstein","LI/LIE","423","34,761(210)","160(218)","4.16Billion(164)")},
{"+370",new CountryData("Lithuania","LT/LTU","370","3,555,179(130)","65,300(123)","63.33Billion(82)")},
{"+352",new CountryData("Luxembourg","LU/LUX","352","491,775(169)","2,586(179)","39.37Billion(96)")},
{"+853",new CountryData("Macau","MO/MAC","853","559,846(167)","28(230)","18.14Billion(126)")},
{"+389",new CountryData("Macedonia","MK/MKD","389","2,066,718(144)","25,713(150)","18.78Billion(124)")},
{"+261",new CountryData("Madagascar","MG/MDG","261","20,653,556(55)","587,041(47)","20.13Billion(122)")},
{"+265",new CountryData("Malawi","MW/MWI","265","14,268,711(66)","118,484(100)","11.81Billion(142)")},
{"+60",new CountryData("Malaysia","MY/MYS","60","25,715,819(46)","329,847(67)","384.3Billion(30)")},
{"+960",new CountryData("Maldives","MV/MDV","960","396,334(174)","298(209)","1.716Billion(185)")},
{"+223",new CountryData("Mali","ML/MLI","223","12,666,987(70)","1,240,192(25)","14.59Billion(133)")},
{"+356",new CountryData("Malta","MT/MLT","356","405,165(173)","316(207)","9.962Billion(148)")},
{"+692",new CountryData("MarshallIslands","MH/MHL","692","64,522(205)","181(216)","133.5Million(217)")},
{"+222",new CountryData("Mauritania","MR/MRT","222","3,129,486(135)","1,030,700(30)","6.308Billion(153)")},
{"+230",new CountryData("Mauritius","MU/MUS","230","1,284,264(153)","2,040(181)","15.27Billion(132)")},
{"+262",new CountryData("Mayotte","YT/MYT","262","223,765(183)","374(204)","953.6Million(201)")},
{"+52",new CountryData("Mexico","MX/MEX","52","111,211,789(11)","1,964,375(16)","1.563Trillion(11)")},
{"+691",new CountryData("Micronesia","FM/FSM","691","107,434(192)","702(192)","238.1Million(213)")},
{"+373",new CountryData("Moldova","MD/MDA","373","4,320,748(122)","33,851(140)","10.67Billion(145)")},
{"+377",new CountryData("Monaco","MC/MCO","377","32,965(211)","2(237)","976.3Million(200)")},
{"+976",new CountryData("Mongolia","MN/MNG","976","3,041,142(136)","1,564,116(20)","9.476Billion(150)")},
{"+382",new CountryData("Montenegro","ME/MNE","382","672,180(164)","13,812(162)","6.816Billion(152)")},
{"+1664",new CountryData("Montserrat","MS/MSR","1664","5,097(226)","102(223)","29Million(223)")},
{"+212",new CountryData("Morocco","MA/MAR","212","34,859,364(35)","446,550(58)","136.6Billion(58)")},
{"+258",new CountryData("Mozambique","MZ/MOZ","258","21,669,278(52)","799,380(36)","18.94Billion(123)")},
{"+264",new CountryData("Namibia","NA/NAM","264","2,108,665(143)","824,292(35)","13.25Billion(135)")},
{"+674",new CountryData("Nauru","NR/NRU","674","14,019(220)","21(232)","60Million(221)")},
{"+977",new CountryData("Nepal","NP/NPL","977","28,563,377(42)","147,181(94)","31.08Billion(103)")},
{"+31",new CountryData("Netherlands","NL/NLD","31","16,715,999(59)","41,543(135)","672Billion(20)")},
{"+599",new CountryData("NetherlandsAntilles","AN/ANT","599","227,049(182)","800(188)","2.8Billion(174)")},
{"+687",new CountryData("NewCaledonia","NC/NCL","687","227,436(181)","18,575(156)","3.158Billion(171)")},
{"+64",new CountryData("NewZealand","NZ/NZL","64","4,213,418(124)","267,710(76)","116.7Billion(60)")},
{"+505",new CountryData("Nicaragua","NI/NIC","505","5,891,199(108)","130,370(98)","16.79Billion(129)")},
{"+227",new CountryData("Niger","NE/NER","227","15,306,252(63)","1,267,000(23)","10.04Billion(147)")},
{"+234",new CountryData("Nigeria","NG/NGA","234","149,229,090(8)","923,768(33)","335.4Billion(35)")},
{"+683",new CountryData("Niue","NU/NIU","683","1,398(232)","260(212)","10.01Million(226)")},
{"+672x",new CountryData("NorfolkIsland","/NFK","672","2,141(228)","36(229)","0(228)")},
{"+850",new CountryData("NorthKorea","KP/PRK","850","22,665,345(50)","120,538(99)","40Billion(94)")},
{"+1670",new CountryData("NorthernMarianaIslands","MP/MNP","1670","88,662(197)","464(198)","900Million(204)")},
{"+47",new CountryData("Norway","NO/NOR","47","4,660,539(116)","323,802(68)","275.4Billion(40)")},
{"+968",new CountryData("Oman","OM/OMN","968","3,418,085(133)","309,500(71)","66.98Billion(81)")},
{"+92",new CountryData("Pakistan","PK/PAK","92","176,242,949(6)","796,095(37)","427.3Billion(27)")},
{"+680",new CountryData("Palau","PW/PLW","680","20,796(217)","459(199)","164Million(216)")},
{"+507",new CountryData("Panama","PA/PAN","507","3,360,474(134)","75,420(118)","38.83Billion(98)")},
{"+675",new CountryData("PapuaNewGuinea","PG/PNG","675","6,057,263(106)","462,840(55)","13.21Billion(136)")},
{"+595",new CountryData("Paraguay","PY/PRY","595","6,995,655(101)","406,752(60)","28.89Billion(107)")},
{"+51",new CountryData("Peru","PE/PER","51","29,546,963(39)","1,285,216(21)","247.3Billion(43)")},
{"+63",new CountryData("Philippines","PH/PHL","63","97,976,603(12)","300,000(73)","317.5Billion(37)")},
{"+870",new CountryData("PitcairnIslands","PN/PCN","870","48(235)","47(228)","0(228)")},
{"+48",new CountryData("Poland","PL/POL","48","38,482,919(34)","312,685(70)","667.9Billion(21)")},
{"+351",new CountryData("Portugal","PT/PRT","351","10,707,924(75)","92,090(111)","236.5Billion(47)")},
{"+1x",new CountryData("PuertoRico","PR/PRI","1","3,971,020(128)","13,790(163)","70.23Billion(78)")},
{"+974",new CountryData("Qatar","QA/QAT","974","833,285(158)","11,586(166)","91.33Billion(69)")},
{"+242",new CountryData("RepublicoftheCongo","CG/COG","242","4,012,809(127)","342,000(64)","15.35Billion(131)")},
{"+40",new CountryData("Romania","RO/ROU","40","22,215,421(51)","238,391(83)","271.4Billion(41)")},
{"+7",new CountryData("Russia","RU/RUS","7","140,041,247(9)","17,098,242(1)","2.266Trillion(6)")},
{"+250",new CountryData("Rwanda","RW/RWA","250","10,473,282(77)","26,338(149)","9.706Billion(149)")},
{"+590",new CountryData("SaintBarthelemy","BL/BLM","590","7,448(224)","0(238)","0(228)")},
{"+290",new CountryData("SaintHelena","SH/SHN","290","7,637(223)","308(208)","18Million(224)")},
{"+1869",new CountryData("SaintKittsandNevis","KN/KNA","1869","40,131(209)","261(211)","777.7Million(206)")},
{"+1758",new CountryData("SaintLucia","LC/LCA","1758","160,267(188)","616(194)","1.778Billion(184)")},
{"+1599",new CountryData("SaintMartin","MF/MAF","1599","29,820(213)","54(227)","0(228)")},
{"+508",new CountryData("SaintPierreandMiquelon","PM/SPM","508","7,051(225)","242(213)","48.3Million(222)")},
{"+1784",new CountryData("SaintVincentandtheGrenadines","VC/VCT","1784","104,574(193)","389(203)","1.07Billion(195)")},
{"+685",new CountryData("Samoa","WS/WSM","685","219,998(184)","2,831(178)","1.049Billion(197)")},
{"+378",new CountryData("SanMarino","SM/SMR","378","30,324(212)","61(225)","1.662Billion(187)")},
{"+239",new CountryData("SaoTomeandPrincipe","ST/STP","239","212,679(186)","964(185)","276.5Million(212)")},
{"+966",new CountryData("SaudiArabia","SA/SAU","966","28,686,633(41)","2,149,690(15)","576.5Billion(22)")},
{"+221",new CountryData("Senegal","SN/SEN","221","13,711,597(67)","196,722(88)","21.98Billion(115)")},
{"+381s",new CountryData("Serbia","RS/SRB","381","7,379,339(95)","77,474(117)","80.34Billion(74)")},
{"+248",new CountryData("Seychelles","SC/SYC","248","87,476(198)","455(200)","1.715Billion(186)")},
{"+232",new CountryData("SierraLeone","SL/SLE","232","6,440,053(103)","71,740(119)","4.285Billion(162)")},
{"+65",new CountryData("Singapore","SG/SGP","65","4,657,542(117)","697(193)","237.3Billion(46)")},
{"+421",new CountryData("Slovakia","SK/SVK","421","5,463,046(111)","49,035(131)","119.5Billion(59)")},
{"+386",new CountryData("Slovenia","SI/SVN","386","2,005,692(145)","20,273(155)","59.34Billion(84)")},
{"+677",new CountryData("SolomonIslands","SB/SLB","677","595,613(166)","28,896(144)","1.078Billion(194)")},
{"+252",new CountryData("Somalia","SO/SOM","252","9,832,017(83)","637,657(44)","5.524Billion(155)")},
{"+27",new CountryData("SouthAfrica","ZA/ZAF","27","49,052,489(24)","1,219,090(26)","491Billion(25)")},
{"+82",new CountryData("SouthKorea","KR/KOR","82","48,508,972(25)","99,720(109)","1.335Trillion(13)")},
{"+34",new CountryData("Spain","ES/ESP","34","40,525,002(32)","505,370(52)","1.403Trillion(12)")},
{"+94",new CountryData("SriLanka","LK/LKA","94","21,324,791(53)","65,610(122)","91.87Billion(68)")},
{"+249",new CountryData("Sudan","SD/SDN","249","41,087,825(29)","2,505,813(11)","88.08Billion(71)")},
{"+597",new CountryData("Suriname","SR/SUR","597","481,267(170)","163,820(92)","4.254Billion(163)")},
{"+s",new CountryData("Svalbard","SJ/SJM","","2,116(229)","62,045(125)","0(228)")},
{"+268",new CountryData("Swaziland","SZ/SWZ","268","1,123,913(156)","17,364(159)","5.702Billion(154)")},
{"+46",new CountryData("Sweden","SE/SWE","46","9,059,651(87)","450,295(56)","344.3Billion(32)")},
{"+41",new CountryData("Switzerland","CH/CHE","41","7,604,467(94)","41,277(136)","316.7Billion(38)")},
{"+963",new CountryData("Syria","SY/SYR","963","20,178,485(57)","185,180(89)","98.83Billion(66)")},
{"+886",new CountryData("Taiwan","TW/TWN","886","22,974,347(49)","35,980(139)","712Billion(19)")},
{"+992",new CountryData("Tajikistan","TJ/TJK","992","7,349,145(96)","143,100(96)","13.16Billion(137)")},
{"+255",new CountryData("Tanzania","TZ/TZA","255","41,048,532(30)","947,300(32)","54.25Billion(87)")},
{"+66",new CountryData("Thailand","TH/THA","66","65,905,410(20)","513,120(51)","547.4Billion(24)")},
{"+670",new CountryData("Timor-Leste","TL/TLS","670","1,131,612(155)","14,874(160)","2.52Billion(177)")},
{"+228",new CountryData("Togo","TG/TGO","228","6,019,877(107)","56,785(126)","5.118Billion(157)")},
{"+690",new CountryData("Tokelau","TK/TKL","690","1,416(230)","12(234)","1.5Million(227)")},
{"+676",new CountryData("Tonga","TO/TON","676","120,898(189)","747(190)","549Million(211)")},
{"+1868",new CountryData("TrinidadandTobago","TT/TTO","1868","1,229,953(154)","5,128(174)","29.01Billion(106)")},
{"+216",new CountryData("Tunisia","TN/TUN","216","10,486,339(76)","163,610(93)","81.71Billion(73)")},
{"+90",new CountryData("Turkey","TR/TUR","90","76,805,524(17)","783,562(38)","902.7Billion(16)")},
{"+993",new CountryData("Turkmenistan","TM/TKM","993","4,884,887(114)","488,100(53)","29.78Billion(104)")},
{"+1649",new CountryData("TurksandCaicosIslands","TC/TCA","1649","22,942(216)","948(186)","216Million(214)")},
{"+688",new CountryData("Tuvalu","TV/TUV","688","12,373(221)","26(231)","14.94Million(225)")},
{"+256",new CountryData("Uganda","UG/UGA","256","32,369,558(38)","241,038(81)","39.38Billion(95)")},
{"+380",new CountryData("Ukraine","UA/UKR","380","45,700,395(27)","603,550(46)","339.8Billion(34)")},
{"+971",new CountryData("UnitedArabEmirates","AE/ARE","971","4,798,491(115)","83,600(115)","184.3Billion(55)")},
{"+44",new CountryData("UnitedKingdom","GB/GBR","44","61,113,205(22)","243,610(80)","2.226Trillion(7)")},
{"+1",new CountryData("UnitedStates","US/USA","1","307,212,123(3)","9,826,675(4)","14.26Trillion(1)")},
{"+598",new CountryData("Uruguay","UY/URY","598","3,494,382(131)","176,215(91)","43.16Billion(92)")},
{"+1340",new CountryData("USVirginIslands","VI/VIR","1340","109,825(191)","1,910(182)","1.577Billion(190)")},
{"+998",new CountryData("Uzbekistan","UZ/UZB","998","27,606,007(44)","447,400(57)","71.67Billion(77)")},
{"+678",new CountryData("Vanuatu","VU/VUT","678","218,519(185)","12,189(164)","988.5Million(199)")},
{"+58",new CountryData("Venezuela","VE/VEN","58","26,814,843(45)","912,050(34)","357.4Billion(31)")},
{"+84",new CountryData("Vietnam","VN/VNM","84","86,967,524(13)","331,210(66)","241.7Billion(45)")},
{"+681",new CountryData("WallisandFutuna","WF/WLF","681","15,289(218)","142(220)","60Million(220)")},
{"+970w",new CountryData("WestBank","/","970","2,461,267(140)","5,860(172)","11.95Billion(140)")},
{"+967",new CountryData("Yemen","YE/YEM","967","23,822,783(48)","527,968(50)","55.28Billion(85)")},
{"+260",new CountryData("Zambia","ZM/ZMB","260","11,862,740(71)","752,618(40)","17.5Billion(128)")},
{"+263",new CountryData("Zimbabwe","ZW/ZWE","263","11,392,629(73)","390,757(61)","1.925Billion(182)")},
};
}
}
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

15:06:02 01.01.2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Hamon
{
/// <summary>
/// Ahoj,
/// mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru,
/// ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny,
/// a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)
/// Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka),
/// databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".
/// Jak toto nejlip vyresit?
/// Predem diky za tipy a pekny novy rok.
/// </summary>
class Program
{
static void Main(string[] args)
{
string[] num = new string[] { "+420 123 456 789", "+352123 456789", "123456789", "12345", "+420123 456789 1234567" };
foreach (string s in num)
Console.WriteLine(CountryCodes.Hamoun(s));

}
public class CountryCodes
{
public static string Hamoun(string unformatted)
{
var num = Regex.Replace(unformatted, @"[^+^0-9]+", "");
var code = "+420";
foreach (var c in codes)
{
if (unformatted.StartsWith(c))
{
num = num.Replace(c, "");
code = c;
break;
}
}
return code + " " + Regex.Replace(num.PadLeft(9,'0'), @"(\d{3})(\d{3})(\d{3})", "$1 $2 $3");
}
static string[] codes = new string[]{
// Country ISO Country Codes Country Code Population Area Sq. Km GDP $USD
/* Afghanistan AF / AFG */"+93",/* 28,396,000 (43) 652,230 (42) 22.27 Billion (114) */
/* Albania AL / ALB */"+355",/* 3,639,453 (129) 28,748 (145) 21.81 Billion (116) */
/* Algeria DZ / DZA */"+213",/* 34,178,188 (36) 2,381,741 (12) 232.9 Billion (48) */
/* American Samoa AS / ASM */"+1684",/* 65,628 (204) 199 (215) 575.3 Million (210) */
/* Andorra AD / AND */"+376",/* 83,888 (200) 468 (197) 3.66 Billion (166) */
/* Angola AO / AGO */"+244",/* 12,799,293 (69) 1,246,700 (24) 110.3 Billion (62) */
/* Anguilla AI / AIA */"+1264",/* 14,436 (219) 91 (224) 108.9 Million (218) */
/* Antarctica AQ / ATA */"+672",/* 0 (236) 14,000,000 (2) 0 (228) */
/* Antigua and Barbuda AG / ATG */"+1268",/* 85,632 (199) 443 (201) 1.657 Billion (188) */
/* Argentina AR / ARG */"+54",/* 40,913,584 (31) 2,780,400 (9) 573.9 Billion (23) */
/* Armenia AM / ARM */"+374",/* 2,967,004 (137) 29,743 (143) 18.77 Billion (125) */
/* Aruba AW / ABW */"+297",/* 103,065 (194) 180 (217) 2.258 Billion (180) */
/* Australia AU / AUS */"+61",/* 21,262,641 (54) 7,741,220 (7) 800.2 Billion (18) */
/* Austria AT / AUT */"+43",/* 8,210,281 (92) 83,871 (114) 329.5 Billion (36) */
/* Azerbaijan AZ / AZE */"+994",/* 8,238,672 (91) 86,600 (113) 77.61 Billion (76) */
/* Bahamas BS / BHS */"+1242",/* 309,156 (176) 13,880 (161) 9.093 Billion (151) */
/* Bahrain BH / BHR */"+973",/* 727,785 (162) 741 (191) 26.82 Billion (111) */
/* Bangladesh BD / BGD */"+880",/* 156,050,883 (7) 143,998 (95) 224 Billion (49) */
/* Barbados BB / BRB */"+1246",/* 284,589 (180) 430 (202) 5.425 Billion (156) */
/* Belarus BY / BLR */"+375",/* 9,648,533 (86) 207,600 (86) 114.1 Billion (61) */
/* Belgium BE / BEL */"+32",/* 10,414,336 (78) 30,528 (141) 389.3 Billion (29) */
/* Belize BZ / BLZ */"+501",/* 307,899 (177) 22,966 (152) 2.536 Billion (176) */
/* Benin BJ / BEN */"+229",/* 8,791,832 (90) 112,622 (102) 12.83 Billion (138) */
/* Bermuda BM / BMU */"+1441",/* 67,837 (203) 54 (226) 4.5 Billion (161) */
/* Bhutan BT / BTN */"+975",/* 691,141 (163) 38,394 (137) 3.524 Billion (168) */
/* Bolivia BO / BOL */"+591",/* 9,775,246 (84) 1,098,581 (29) 43.27 Billion (91) */
/* Bosnia and Herzegovina BA / BIH */"+387",/* 4,613,414 (119) 51,197 (129) 29.7 Billion (105) */
/* Botswana BW / BWA */"+267",/* 1,990,876 (146) 581,730 (48) 27.06 Billion (110) */
/* Brazil BR / BRA */"+55",/* 198,739,269 (5) 8,514,877 (6) 1.993 Trillion (9) */
/* British Virgin Islands VG / VGB */"+1284",/* 24,491 (215) 151 (219) 853.4 Million (205) */
/* Brunei BN / BRN */"+673",/* 388,190 (175) 5,765 (173) 20.25 Billion (121) */
/* Bulgaria BG / BGR */"+359",/* 7,204,687 (98) 110,879 (105) 93.75 Billion (67) */
/* Burkina Faso BF / BFA */"+226",/* 15,746,232 (61) 274,200 (75) 17.82 Billion (127) */
/* Burma (Myanmar) MM / MMR */"+95",/* 48,137,741 (26) 676,578 (41) 55.13 Billion (86) */
/* Burundi BI / BDI */"+257",/* 8,988,091 (89) 27,830 (147) 3.102 Billion (172) */
/* Cambodia KH / KHM */"+855",/* 14,494,293 (65) 181,035 (90) 27.94 Billion (108) */
/* Cameroon CM / CMR */"+237",/* 18,879,301 (58) 475,440 (54) 42.75 Billion (93) */
/* Canada CA / CAN */"+1",/* 33,487,208 (37) 9,984,670 (3) 1.3 Trillion (14) */
/* Cape Verde CV / CPV */"+238",/* 429,474 (171) 4,033 (176) 1.626 Billion (189) */
/* Cayman Islands KY / CYM */"+1345",/* 49,035 (207) 264 (210) 1.939 Billion (181) */
/* Central African Republic CF / CAF */"+236",/* 4,511,488 (120) 622,984 (45) 3.198 Billion (170) */
/* Chad TD / TCD */"+235",/* 10,329,208 (79) 1,284,000 (22) 15.86 Billion (130) */
/* Chile CL / CHL */"+56",/* 16,601,707 (60) 756,102 (39) 244.5 Billion (44) */
/* China CN / CHN */"+86",/* 1,338,612,968 (1) 9,596,961 (5) 7.973 Trillion (2) */
/* Christmas Island CX / CXR */"+61",/* 1,402 (231) 135 (221) 0 (228) */
/* Cocos (Keeling) Islands CC / CCK */"+61",/* 596 (234) 14 (233) 0 (228) */
/* Colombia CO / COL */"+57",/* 45,644,023 (28) 1,138,914 (27) 395.4 Billion (28) */
/* Comoros KM / COM */"+269",/* 752,438 (161) 2,235 (180) 751.2 Million (207) */
/* Cook Islands CK / COK */"+682",/* 11,870 (222) 236 (214) 183.2 Million (215) */
/* Costa Rica CR / CRC */"+506",/* 4,253,877 (123) 51,100 (130) 48.32 Billion (88) */
/* Croatia HR / HRV */"+385",/* 4,489,409 (121) 56,594 (127) 82.39 Billion (72) */
/* Cuba CU / CUB */"+53",/* 11,451,652 (72) 110,860 (106) 108.2 Billion (63) */
/* Cyprus CY / CYP */"+357",/* 796,740 (159) 9,251 (171) 22.7 Billion (113) */
/* Czech Republic CZ / CZE */"+420",/* 10,211,904 (80) 78,867 (116) 265.2 Billion (42) */
/* Democratic Republic of the Congo CD / COD */"+243",/* 68,692,542 (18) 2,344,858 (13) 20.64 Billion (120) */
/* Denmark DK / DNK */"+45",/* 5,500,510 (110) 43,094 (134) 203.6 Billion (50) */
/* Djibouti DJ / DJI */"+253",/* 516,055 (168) 23,200 (151) 1.885 Billion (183) */
/* Dominica DM / DMA */"+1767",/* 72,660 (202) 751 (189) 719.6 Million (208) */
/* Dominican Republic DO / DOM */"+1809",/* 9,650,054 (85) 48,670 (132) 78 Billion (75) */
/* Ecuador EC / ECU */"+593",/* 14,573,101 (64) 283,561 (74) 107.7 Billion (64) */
/* Egypt EG / EGY */"+20",/* 83,082,869 (15) 1,001,450 (31) 443.7 Billion (26) */
/* El Salvador SV / SLV */"+503",/* 7,185,218 (99) 21,041 (154) 43.63 Billion (90) */
/* Equatorial Guinea GQ / GNQ */"+240",/* 633,441 (165) 28,051 (146) 22.95 Billion (112) */
/* Eritrea ER / ERI */"+291",/* 5,647,168 (109) 117,600 (101) 3.945 Billion (165) */
/* Estonia EE / EST */"+372",/* 1,299,371 (152) 45,228 (133) 27.41 Billion (109) */
/* Ethiopia ET / ETH */"+251",/* 85,237,338 (14) 1,104,300 (28) 68.77 Billion (79) */
/* Falkland Islands FK / FLK */"+500",/* 3,140 (227) 12,173 (165) 105.1 Million (219) */
/* Faroe Islands FO / FRO */"+298",/* 48,856 (208) 1,393 (183) 1000 Million (198) */
/* Fiji FJ / FJI */"+679",/* 944,720 (157) 18,274 (157) 3.579 Billion (167) */
/* Finland FI / FIN */"+358",/* 5,250,275 (113) 338,145 (65) 193.5 Billion (53) */
/* France FR / FRA */"+33",/* 64,057,792 (21) 643,427 (43) 2.128 Trillion (8) */
/* French Polynesia PF / PYF */"+689",/* 287,032 (179) 4,167 (175) 4.718 Billion (160) */
/* Gabon GA / GAB */"+241",/* 1,514,993 (151) 267,667 (77) 21.11 Billion (118) */
/* Gambia GM / GMB */"+220",/* 1,782,893 (148) 11,295 (167) 2.272 Billion (179) */
/* Gaza Strip / */"+970",/* 1,551,859 (149) 360 (205) 11.95 Billion (141) */
/* Georgia GE / GEO */"+995",/* 4,615,807 (118) 69,700 (121) 21.51 Billion (117) */
/* Germany DE / DEU */"+49",/* 82,329,758 (16) 357,022 (63) 2.918 Trillion (5) */
/* Ghana GH / GHA */"+233",/* 23,832,495 (47) 238,533 (82) 34.2 Billion (99) */
/* Gibraltar GI / GIB */"+350",/* 28,034 (214) 7 (235) 1.066 Billion (196) */
/* Greece GR / GRC */"+30",/* 10,737,428 (74) 131,957 (97) 343 Billion (33) */
/* Greenland GL / GRL */"+299",/* 57,600 (206) 2,166,086 (14) 1.1 Billion (193) */
/* Grenada GD / GRD */"+1473",/* 90,739 (196) 344 (206) 1.161 Billion (192) */
/* Guam GU / GUM */"+1671",/* 160,595 (187) 544 (196) 2.5 Billion (178) */
/* Guatemala GT / GTM */"+502",/* 13,276,517 (68) 108,889 (107) 68.58 Billion (80) */
/* Guinea GN / GIN */"+224",/* 10,057,975 (81) 245,857 (79) 10.6 Billion (146) */
/* Guinea-Bissau GW / GNB */"+245",/* 1,533,964 (150) 36,125 (138) 904.2 Million (202) */
/* Guyana GY / GUY */"+592",/* 772,298 (160) 214,969 (85) 2.966 Billion (173) */
/* Haiti HT / HTI */"+509",/* 9,035,536 (88) 27,750 (148) 11.5 Billion (144) */
/* Holy See (Vatican City) VA / VAT */"+39",/* 826 (233) 0 (238) 0 (228) */
/* Honduras HN / HND */"+504",/* 7,792,854 (93) 112,090 (103) 33.72 Billion (101) */
/* Hong Kong HK / HKG */"+852",/* 7,055,071 (100) 1,104 (184) 306.6 Billion (39) */
/* Hungary HU / HUN */"+36",/* 9,905,596 (82) 93,028 (110) 196.6 Billion (52) */
/* Iceland IS / IS */"+354",/* 306,694 (178) 103,000 (108) 12.71 Billion (139) */
/* India IN / IND */"+91",/* 1,166,079,217 (2) 3,287,263 (8) 3.297 Trillion (4) */
/* Indonesia ID / IDN */"+62",/* 240,271,522 (4) 1,904,569 (17) 914.6 Billion (15) */
/* Iran IR / IRN */"+98",/* 66,429,284 (19) 1,648,195 (19) 841.7 Billion (17) */
/* Iraq IQ / IRQ */"+964",/* 28,945,657 (40) 438,317 (59) 103.9 Billion (65) */
/* Ireland IE / IRL */"+353",/* 4,203,200 (125) 70,273 (120) 188.4 Billion (54) */
/* Isle of Man IM / IMN */"+44",/* 76,512 (201) 572 (195) 2.719 Billion (175) */
/* Israel IL / ISR */"+972",/* 7,233,701 (97) 22,072 (153) 201.4 Billion (51) */
/* Italy IT / ITA */"+39",/* 58,126,212 (23) 301,340 (72) 1.823 Trillion (10) */
/* Ivory Coast CI / CIV */"+225",/* 20,617,068 (56) 322,463 (69) 33.85 Billion (100) */
/* Jamaica JM / JAM */"+1876",/* 2,825,928 (138) 10,991 (168) 20.91 Billion (119) */
/* Japan JP / JPN */"+81",/* 127,078,679 (10) 377,915 (62) 4.329 Trillion (3) */
/* Jordan JO / JOR */"+962",/* 6,342,948 (104) 89,342 (112) 31.61 Billion (102) */
/* Kazakhstan KZ / KAZ */"+7",/* 15,399,437 (62) 2,724,900 (10) 175.8 Billion (56) */
/* Kenya KE / KEN */"+254",/* 39,002,772 (33) 580,367 (49) 61.51 Billion (83) */
/* Kiribati KI / KIR */"+686",/* 112,850 (190) 811 (187) 579.5 Million (209) */
/* Kosovo / */"+381",/* 1,804,838 (147) 10,887 (169) 5 Billion (159) */
/* Kuwait KW / KWT */"+965",/* 2,691,158 (139) 17,818 (158) 149.1 Billion (57) */
/* Kyrgyzstan KG / KGZ */"+996",/* 5,431,747 (112) 199,951 (87) 11.61 Billion (143) */
/* Laos LA / LAO */"+856",/* 6,834,942 (102) 236,800 (84) 13.98 Billion (134) */
/* Latvia LV / LVA */"+371",/* 2,231,503 (141) 64,589 (124) 38.86 Billion (97) */
/* Lebanon LB / LBN */"+961",/* 4,017,095 (126) 10,400 (170) 44.06 Billion (89) */
/* Lesotho LS / LSO */"+266",/* 2,130,819 (142) 30,355 (142) 3.293 Billion (169) */
/* Liberia LR / LBR */"+231",/* 3,441,790 (132) 111,369 (104) 1.526 Billion (191) */
/* Libya LY / LBY */"+218",/* 6,310,434 (105) 1,759,540 (18) 88.83 Billion (70) */
/* Liechtenstein LI / LIE */"+423",/* 34,761 (210) 160 (218) 4.16 Billion (164) */
/* Lithuania LT / LTU */"+370",/* 3,555,179 (130) 65,300 (123) 63.33 Billion (82) */
/* Luxembourg LU / LUX */"+352",/* 491,775 (169) 2,586 (179) 39.37 Billion (96) */
/* Macau MO / MAC */"+853",/* 559,846 (167) 28 (230) 18.14 Billion (126) */
/* Macedonia MK / MKD */"+389",/* 2,066,718 (144) 25,713 (150) 18.78 Billion (124) */
/* Madagascar MG / MDG */"+261",/* 20,653,556 (55) 587,041 (47) 20.13 Billion (122) */
/* Malawi MW / MWI */"+265",/* 14,268,711 (66) 118,484 (100) 11.81 Billion (142) */
/* Malaysia MY / MYS */"+60",/* 25,715,819 (46) 329,847 (67) 384.3 Billion (30) */
/* Maldives MV / MDV */"+960",/* 396,334 (174) 298 (209) 1.716 Billion (185) */
/* Mali ML / MLI */"+223",/* 12,666,987 (70) 1,240,192 (25) 14.59 Billion (133) */
/* Malta MT / MLT */"+356",/* 405,165 (173) 316 (207) 9.962 Billion (148) */
/* Marshall Islands MH / MHL */"+692",/* 64,522 (205) 181 (216) 133.5 Million (217) */
/* Mauritania MR / MRT */"+222",/* 3,129,486 (135) 1,030,700 (30) 6.308 Billion (153) */
/* Mauritius MU / MUS */"+230",/* 1,284,264 (153) 2,040 (181) 15.27 Billion (132) */
/* Mayotte YT / MYT */"+262",/* 223,765 (183) 374 (204) 953.6 Million (201) */
/* Mexico MX / MEX */"+52",/* 111,211,789 (11) 1,964,375 (16) 1.563 Trillion (11) */
/* Micronesia FM / FSM */"+691",/* 107,434 (192) 702 (192) 238.1 Million (213) */
/* Moldova MD / MDA */"+373",/* 4,320,748 (122) 33,851 (140) 10.67 Billion (145) */
/* Monaco MC / MCO */"+377",/* 32,965 (211) 2 (237) 976.3 Million (200) */
/* Mongolia MN / MNG */"+976",/* 3,041,142 (136) 1,564,116 (20) 9.476 Billion (150) */
/* Montenegro ME / MNE */"+382",/* 672,180 (164) 13,812 (162) 6.816 Billion (152) */
/* Montserrat MS / MSR */"+1664",/* 5,097 (226) 102 (223) 29 Million (223) */
/* Morocco MA / MAR */"+212",/* 34,859,364 (35) 446,550 (58) 136.6 Billion (58) */
/* Mozambique MZ / MOZ */"+258",/* 21,669,278 (52) 799,380 (36) 18.94 Billion (123) */
/* Namibia NA / NAM */"+264",/* 2,108,665 (143) 824,292 (35) 13.25 Billion (135) */
/* Nauru NR / NRU */"+674",/* 14,019 (220) 21 (232) 60 Million (221) */
/* Nepal NP / NPL */"+977",/* 28,563,377 (42) 147,181 (94) 31.08 Billion (103) */
/* Netherlands NL / NLD */"+31",/* 16,715,999 (59) 41,543 (135) 672 Billion (20) */
/* Netherlands Antilles AN / ANT */"+599",/* 227,049 (182) 800 (188) 2.8 Billion (174) */
/* New Caledonia NC / NCL */"+687",/* 227,436 (181) 18,575 (156) 3.158 Billion (171) */
/* New Zealand NZ / NZL */"+64",/* 4,213,418 (124) 267,710 (76) 116.7 Billion (60) */
/* Nicaragua NI / NIC */"+505",/* 5,891,199 (108) 130,370 (98) 16.79 Billion (129) */
/* Niger NE / NER */"+227",/* 15,306,252 (63) 1,267,000 (23) 10.04 Billion (147) */
/* Nigeria NG / NGA */"+234",/* 149,229,090 (8) 923,768 (33) 335.4 Billion (35) */
/* Niue NU / NIU */"+683",/* 1,398 (232) 260 (212) 10.01 Million (226) */
/* Norfolk Island / NFK */"+672",/* 2,141 (228) 36 (229) 0 (228) */
/* North Korea KP / PRK */"+850",/* 22,665,345 (50) 120,538 (99) 40 Billion (94) */
/* Northern Mariana Islands MP / MNP */"+1670",/* 88,662 (197) 464 (198) 900 Million (204) */
/* Norway NO / NOR */"+47",/* 4,660,539 (116) 323,802 (68) 275.4 Billion (40) */
/* Oman OM / OMN */"+968",/* 3,418,085 (133) 309,500 (71) 66.98 Billion (81) */
/* Pakistan PK / PAK */"+92",/* 176,242,949 (6) 796,095 (37) 427.3 Billion (27) */
/* Palau PW / PLW */"+680",/* 20,796 (217) 459 (199) 164 Million (216) */
/* Panama PA / PAN */"+507",/* 3,360,474 (134) 75,420 (118) 38.83 Billion (98) */
/* Papua New Guinea PG / PNG */"+675",/* 6,057,263 (106) 462,840 (55) 13.21 Billion (136) */
/* Paraguay PY / PRY */"+595",/* 6,995,655 (101) 406,752 (60) 28.89 Billion (107) */
/* Peru PE / PER */"+51",/* 29,546,963 (39) 1,285,216 (21) 247.3 Billion (43) */
/* Philippines PH / PHL */"+63",/* 97,976,603 (12) 300,000 (73) 317.5 Billion (37) */
/* Pitcairn Islands PN / PCN */"+870",/* 48 (235) 47 (228) 0 (228) */
/* Poland PL / POL */"+48",/* 38,482,919 (34) 312,685 (70) 667.9 Billion (21) */
/* Portugal PT / PRT */"+351",/* 10,707,924 (75) 92,090 (111) 236.5 Billion (47) */
/* Puerto Rico PR / PRI */"+1",/* 3,971,020 (128) 13,790 (163) 70.23 Billion (78) */
/* Qatar QA / QAT */"+974",/* 833,285 (158) 11,586 (166) 91.33 Billion (69) */
/* Republic of the Congo CG / COG */"+242",/* 4,012,809 (127) 342,000 (64) 15.35 Billion (131) */
/* Romania RO / ROU */"+40",/* 22,215,421 (51) 238,391 (83) 271.4 Billion (41) */
/* Russia RU / RUS */"+7",/* 140,041,247 (9) 17,098,242 (1) 2.266 Trillion (6) */
/* Rwanda RW / RWA */"+250",/* 10,473,282 (77) 26,338 (149) 9.706 Billion (149) */
/* Saint Barthelemy BL / BLM */"+590",/* 7,448 (224) 0 (238) 0 (228) */
/* Saint Helena SH / SHN */"+290",/* 7,637 (223) 308 (208) 18 Million (224) */
/* Saint Kitts and Nevis KN / KNA */"+1869",/* 40,131 (209) 261 (211) 777.7 Million (206) */
/* Saint Lucia LC / LCA */"+1758",/* 160,267 (188) 616 (194) 1.778 Billion (184) */
/* Saint Martin MF / MAF */"+1599",/* 29,820 (213) 54 (227) 0 (228) */
/* Saint Pierre and Miquelon PM / SPM */"+508",/* 7,051 (225) 242 (213) 48.3 Million (222) */
/* Saint Vincent and the Grenadines VC / VCT */"+1784",/* 104,574 (193) 389 (203) 1.07 Billion (195) */
/* Samoa WS / WSM */"+685",/* 219,998 (184) 2,831 (178) 1.049 Billion (197) */
/* San Marino SM / SMR */"+378",/* 30,324 (212) 61 (225) 1.662 Billion (187) */
/* Sao Tome and Principe ST / STP */"+239",/* 212,679 (186) 964 (185) 276.5 Million (212) */
/* Saudi Arabia SA / SAU */"+966",/* 28,686,633 (41) 2,149,690 (15) 576.5 Billion (22) */
/* Senegal SN / SEN */"+221",/* 13,711,597 (67) 196,722 (88) 21.98 Billion (115) */
/* Serbia RS / SRB */"+381",/* 7,379,339 (95) 77,474 (117) 80.34 Billion (74) */
/* Seychelles SC / SYC */"+248",/* 87,476 (198) 455 (200) 1.715 Billion (186) */
/* Sierra Leone SL / SLE */"+232",/* 6,440,053 (103) 71,740 (119) 4.285 Billion (162) */
/* Singapore SG / SGP */"+65",/* 4,657,542 (117) 697 (193) 237.3 Billion (46) */
/* Slovakia SK / SVK */"+421",/* 5,463,046 (111) 49,035 (131) 119.5 Billion (59) */
/* Slovenia SI / SVN */"+386",/* 2,005,692 (145) 20,273 (155) 59.34 Billion (84) */
/* Solomon Islands SB / SLB */"+677",/* 595,613 (166) 28,896 (144) 1.078 Billion (194) */
/* Somalia SO / SOM */"+252",/* 9,832,017 (83) 637,657 (44) 5.524 Billion (155) */
/* South Africa ZA / ZAF */"+27",/* 49,052,489 (24) 1,219,090 (26) 491 Billion (25) */
/* South Korea KR / KOR */"+82",/* 48,508,972 (25) 99,720 (109) 1.335 Trillion (13) */
/* Spain ES / ESP */"+34",/* 40,525,002 (32) 505,370 (52) 1.403 Trillion (12) */
/* Sri Lanka LK / LKA */"+94",/* 21,324,791 (53) 65,610 (122) 91.87 Billion (68) */
/* Sudan SD / SDN */"+249",/* 41,087,825 (29) 2,505,813 (11) 88.08 Billion (71) */
/* Suriname SR / SUR */"+597",/* 481,267 (170) 163,820 (92) 4.254 Billion (163) */
/* Svalbard SJ / SJM */"+",/* 2,116 (229) 62,045 (125) 0 (228) */
/* Swaziland SZ / SWZ */"+268",/* 1,123,913 (156) 17,364 (159) 5.702 Billion (154) */
/* Sweden SE / SWE */"+46",/* 9,059,651 (87) 450,295 (56) 344.3 Billion (32) */
/* Switzerland CH / CHE */"+41",/* 7,604,467 (94) 41,277 (136) 316.7 Billion (38) */
/* Syria SY / SYR */"+963",/* 20,178,485 (57) 185,180 (89) 98.83 Billion (66) */
/* Taiwan TW / TWN */"+886",/* 22,974,347 (49) 35,980 (139) 712 Billion (19) */
/* Tajikistan TJ / TJK */"+992",/* 7,349,145 (96) 143,100 (96) 13.16 Billion (137) */
/* Tanzania TZ / TZA */"+255",/* 41,048,532 (30) 947,300 (32) 54.25 Billion (87) */
/* Thailand TH / THA */"+66",/* 65,905,410 (20) 513,120 (51) 547.4 Billion (24) */
/* Timor-Leste TL / TLS */"+670",/* 1,131,612 (155) 14,874 (160) 2.52 Billion (177) */
/* Togo TG / TGO */"+228",/* 6,019,877 (107) 56,785 (126) 5.118 Billion (157) */
/* Tokelau TK / TKL */"+690",/* 1,416 (230) 12 (234) 1.5 Million (227) */
/* Tonga TO / TON */"+676",/* 120,898 (189) 747 (190) 549 Million (211) */
/* Trinidad and Tobago TT / TTO */"+1868",/* 1,229,953 (154) 5,128 (174) 29.01 Billion (106) */
/* Tunisia TN / TUN */"+216",/* 10,486,339 (76) 163,610 (93) 81.71 Billion (73) */
/* Turkey TR / TUR */"+90",/* 76,805,524 (17) 783,562 (38) 902.7 Billion (16) */
/* Turkmenistan TM / TKM */"+993",/* 4,884,887 (114) 488,100 (53) 29.78 Billion (104) */
/* Turks and Caicos Islands TC / TCA */"+1649",/* 22,942 (216) 948 (186) 216 Million (214) */
/* Tuvalu TV / TUV */"+688",/* 12,373 (221) 26 (231) 14.94 Million (225) */
/* Uganda UG / UGA */"+256",/* 32,369,558 (38) 241,038 (81) 39.38 Billion (95) */
/* Ukraine UA / UKR */"+380",/* 45,700,395 (27) 603,550 (46) 339.8 Billion (34) */
/* United Arab Emirates AE / ARE */"+971",/* 4,798,491 (115) 83,600 (115) 184.3 Billion (55) */
/* United Kingdom GB / GBR */"+44",/* 61,113,205 (22) 243,610 (80) 2.226 Trillion (7) */
/* United States US / USA */"+1",/* 307,212,123 (3) 9,826,675 (4) 14.26 Trillion (1) */
/* Uruguay UY / URY */"+598",/* 3,494,382 (131) 176,215 (91) 43.16 Billion (92) */
/* US Virgin Islands VI / VIR */"+1340",/* 109,825 (191) 1,910 (182) 1.577 Billion (190) */
/* Uzbekistan UZ / UZB */"+998",/* 27,606,007 (44) 447,400 (57) 71.67 Billion (77) */
/* Vanuatu VU / VUT */"+678",/* 218,519 (185) 12,189 (164) 988.5 Million (199) */
/* Venezuela VE / VEN */"+58",/* 26,814,843 (45) 912,050 (34) 357.4 Billion (31) */
/* Vietnam VN / VNM */"+84",/* 86,967,524 (13) 331,210 (66) 241.7 Billion (45) */
/* Wallis and Futuna WF / WLF */"+681",/* 15,289 (218) 142 (220) 60 Million (220) */
/* West Bank / */"+970",/* 2,461,267 (140) 5,860 (172) 11.95 Billion (140) */
/* Western Sahara EH / ESH */"+",/* 405,210 (172) 266,000 (78) 900 Million (203) */
/* Yemen YE / YEM */"+967",/* 23,822,783 (48) 527,968 (50) 55.28 Billion (85) */
/* Zambia ZM / ZMB */"+260",/* 11,862,740 (71) 752,618 (40) 17.5 Billion (128) */
/* Zimbabwe ZW / ZWE */"+263"};/* 11,392,629 (73) 390,757 (61) 1.925 Billion (182) */
}
}
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

12:26:23 01.01.2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Hamon
{
/// <summary>
/// Ahoj,
/// mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru,
/// ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny,
/// a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)
/// Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka),
/// databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".
/// Jak toto nejlip vyresit?
/// Predem diky za tipy a pekny novy rok.
/// </summary>
class Program
{
const string mask = "+420 @@@ @@@ @@@";
static void Main(string[] args)
{
Console.WriteLine(mask);
string[] num = new string[] { "+420 123 456 789", "+420123 456789", "123456789", "12345" , "+420123 456789 1234567"};
foreach (string s in num)
Console.WriteLine(Hamon4(s));

Console.WriteLine("+++");
foreach (string s in num)
Console.WriteLine(Hamon3(s));

Console.WriteLine("+++");
for (int g = 1; g < 10; g++)
{
foreach (string s in num)
Console.WriteLine(Hamon2(s, g));
Console.WriteLine("---");
}
foreach (string s in num)
Console.WriteLine(Hamon1(mask, s));
foreach (string s in num)
Console.WriteLine(Hamon(mask, s));

Console.WriteLine("Hotovo");
Console.ReadKey();
}
static string Hamon4(string num)
{
num = Regex.Replace(num, @"[^+^0-9]+", "").Replace("+420", "").PadLeft(9, '0');
return "+420 " + Regex.Replace(num, @"(\d{3})(\d{3})(\d{3})", "$1 $2 $3");
}
static string Hamon3(string num)
{
num = Regex.Replace(num, @"[^+^0-9]+", "").Replace("+420", "");
return num.Length>9?"?":string.Format("+420 {0:000 000 000}", int.Parse(num));
}
static string Hamon2(string num, int grouping)
{
num = Regex.Replace(num, @"[^+^0-9]+", "").Replace("+420", "").PadLeft(9, '0');
var sb = new StringBuilder("+420");
int i = 0;
foreach (var c in num)
{
if (0 == (i++) % grouping) sb.Append(' ');
sb.Append(c);
}
return sb.ToString();
}
static string Hamon1(string mask, string num)
{
num = Regex.Replace(num, @"[^+^0-9]+", "");
num = num.Replace("+420", "");
num = num.PadLeft(9, '0');
var sb = new StringBuilder();
int i = 0;
foreach (var c in mask)
{
if (c == '@')
{
sb.Append(num[i++]);
if (i >= num.Length) break;
}
else sb.Append(c);
}
return sb.ToString();
}
static string Hamon(string mask, string num)
{
//ziskani cisla bez neuzitecnych znaku
StringBuilder sb = new StringBuilder();
if (num.Trim().StartsWith("+")) sb.Append("+");

List<char> castiCisla = new List<char>();
castiCisla.AddRange(num.ToCharArray());
foreach (char c in castiCisla)
{
if (char.IsDigit(c))
{
sb.Append(c);
}
}
string pouzeCislo = sb.ToString();

//cislo bez neuzitecnych znaku na pole, protoze budu jednotlive znaky vybirat a vkladat do seznamu pouzitelnych
char[] cisloArray = pouzeCislo.ToCharArray();

//masku na pole, protoze budu kontrolovat, jestli je na aktualni pozici v masce znak nebo mezera
char[] maskaArray = mask.ToCharArray();

List<string> pouzitelnaCisla = new List<string>();
//odzadu, protoze maska nemusi obsahovat predvolbu
int poradiVCisle = cisloArray.Length - 1;
for (int m = maskaArray.Length - 1; m >= 0; m--)
{

char znakZMasky = maskaArray[m];
if (char.IsDigit(znakZMasky))
pouzitelnaCisla.Add(znakZMasky.ToString());
else if (znakZMasky.ToString() == " ")
pouzitelnaCisla.Add(" ");
else if (znakZMasky.ToString() == "+")
pouzitelnaCisla.Add("+");
else if (znakZMasky.ToString() == "*")
pouzitelnaCisla.Add("*");
else if (znakZMasky.ToString() == "#")
pouzitelnaCisla.Add("#");
else if (znakZMasky.ToString() == "@")
{
if (poradiVCisle >= 0)
{
pouzitelnaCisla.Add(cisloArray[poradiVCisle].ToString());
poradiVCisle--;
}
else
{
//zbyle pozice z masky, ktere nejsou obsazeny v cisle, muzu doplnit nulami
pouzitelnaCisla.Add(0.ToString());
}
}
}

StringBuilder konecneCislo = new StringBuilder();
//todo: obracene :)
for (int i = pouzitelnaCisla.Count - 1; i >= 0; i--)
{
konecneCislo.Append(pouzitelnaCisla[i]);
}
return konecneCislo.ToString();
}
}
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

12:02:46 01.01.2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Hamon
{
/// <summary>
/// Ahoj,
/// mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru,
/// ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny,
/// a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)
/// Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka),
/// databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".
/// Jak toto nejlip vyresit?
/// Predem diky za tipy a pekny novy rok.
/// </summary>
class Program
{
const string mask = "+420 @@@ @@@ @@@";
static void Main(string[] args)
{
Console.WriteLine(mask);
string[] num = new string[] { "+420 123 456 789", "+420123 456789", "123456789", "12345" };
foreach (string s in num)
Console.WriteLine(Hamon3(s));

Console.WriteLine("+++");
for (int g = 1; g < 10; g++)
{
foreach (string s in num)
Console.WriteLine(Hamon2(s, g));
Console.WriteLine("---");
}
foreach (string s in num)
Console.WriteLine(Hamon1(mask, s));
foreach (string s in num)
Console.WriteLine(Hamon(mask, s));

Console.WriteLine("Hotovo");
Console.ReadKey();
}
static string Hamon3(string num)
{
num = Regex.Replace(num, @"[^+^0-9]+", "").Replace("+420", "");
return string.Format("+420 {0:000 000 000}", int.Parse(num));
}
static string Hamon2(string num, int grouping)
{
num = Regex.Replace(num, @"[^+^0-9]+", "").Replace("+420", "").PadLeft(9, '0');
var sb = new StringBuilder("+420");
int i = 0;
foreach (var c in num)
{
if (0 == (i++) % grouping) sb.Append(' ');
sb.Append(c);
}
return sb.ToString();
}
static string Hamon1(string mask, string num)
{
num = Regex.Replace(num, @"[^+^0-9]+", "");
num = num.Replace("+420", "");
num = num.PadLeft(9, '0');
var sb = new StringBuilder();
int i = 0;
foreach (var c in mask)
{
if (c == '@')
{
sb.Append(num[i++]);
if (i >= num.Length) break;
}
else sb.Append(c);
}
return sb.ToString();
}
static string Hamon(string mask, string num)
{
//ziskani cisla bez neuzitecnych znaku
StringBuilder sb = new StringBuilder();
if (num.Trim().StartsWith("+")) sb.Append("+");

List<char> castiCisla = new List<char>();
castiCisla.AddRange(num.ToCharArray());
foreach (char c in castiCisla)
{
if (char.IsDigit(c))
{
sb.Append(c);
}
}
string pouzeCislo = sb.ToString();

//cislo bez neuzitecnych znaku na pole, protoze budu jednotlive znaky vybirat a vkladat do seznamu pouzitelnych
char[] cisloArray = pouzeCislo.ToCharArray();

//masku na pole, protoze budu kontrolovat, jestli je na aktualni pozici v masce znak nebo mezera
char[] maskaArray = mask.ToCharArray();

List<string> pouzitelnaCisla = new List<string>();
//odzadu, protoze maska nemusi obsahovat predvolbu
int poradiVCisle = cisloArray.Length - 1;
for (int m = maskaArray.Length - 1; m >= 0; m--)
{

char znakZMasky = maskaArray[m];
if (char.IsDigit(znakZMasky))
pouzitelnaCisla.Add(znakZMasky.ToString());
else if (znakZMasky.ToString() == " ")
pouzitelnaCisla.Add(" ");
else if (znakZMasky.ToString() == "+")
pouzitelnaCisla.Add("+");
else if (znakZMasky.ToString() == "*")
pouzitelnaCisla.Add("*");
else if (znakZMasky.ToString() == "#")
pouzitelnaCisla.Add("#");
else if (znakZMasky.ToString() == "@")
{
if (poradiVCisle >= 0)
{
pouzitelnaCisla.Add(cisloArray[poradiVCisle].ToString());
poradiVCisle--;
}
else
{
//zbyle pozice z masky, ktere nejsou obsazeny v cisle, muzu doplnit nulami
pouzitelnaCisla.Add(0.ToString());
}
}
}

StringBuilder konecneCislo = new StringBuilder();
//todo: obracene :)
for (int i = pouzitelnaCisla.Count - 1; i >= 0; i--)
{
konecneCislo.Append(pouzitelnaCisla[i]);
}
return konecneCislo.ToString();
}
}
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

11:29:59 01.01.2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Hamon
{
/// <summary>
/// Ahoj,
/// mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru,
/// ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny,
/// a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)
/// Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka),
/// databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".
/// Jak toto nejlip vyresit?
/// Predem diky za tipy a pekny novy rok.
/// </summary>
class Program
{
const string mask = "+420 @@@ @@@ @@@";
static void Main(string[] args)
{
Console.WriteLine(mask);
string[] num = new string[] { "+420 123 456 789", "+420123 456789", "123456789", "12345" };
for (int g = 1; g < 10; g++)
{
foreach (string s in num)
Console.WriteLine(Hamon2(s, g));
Console.WriteLine("---");
}
foreach (string s in num)
Console.WriteLine(Hamon1(mask, s));
foreach (string s in num)
Console.WriteLine(Hamon(mask, s));

Console.WriteLine("Hotovo");
Console.ReadKey();
}
static string Hamon2(string num, int grouping)
{
num = Regex.Replace(num, @"[^+^0-9]+", "").Replace("+420", "").PadLeft(9, '0');
var sb = new StringBuilder("+420");
int i = 0;
foreach (var c in num)
{
if (0 == (i++) % grouping) sb.Append(' ');
sb.Append(c);
}
return sb.ToString();
}
static string Hamon1(string mask, string num)
{
num = Regex.Replace(num, @"[^+^0-9]+", "");
num = num.Replace("+420", "");
num = num.PadLeft(9, '0');
var sb = new StringBuilder();
int i = 0;
foreach (var c in mask)
{
if (c == '@')
{
sb.Append(num[i++]);
if (i >= num.Length) break;
}
else sb.Append(c);
}
return sb.ToString();
}
static string Hamon(string mask, string num)
{
//ziskani cisla bez neuzitecnych znaku
StringBuilder sb = new StringBuilder();
if (num.Trim().StartsWith("+")) sb.Append("+");

List<char> castiCisla = new List<char>();
castiCisla.AddRange(num.ToCharArray());
foreach (char c in castiCisla)
{
if (char.IsDigit(c))
{
sb.Append(c);
}
}
string pouzeCislo = sb.ToString();

//cislo bez neuzitecnych znaku na pole, protoze budu jednotlive znaky vybirat a vkladat do seznamu pouzitelnych
char[] cisloArray = pouzeCislo.ToCharArray();

//masku na pole, protoze budu kontrolovat, jestli je na aktualni pozici v masce znak nebo mezera
char[] maskaArray = mask.ToCharArray();

List<string> pouzitelnaCisla = new List<string>();
//odzadu, protoze maska nemusi obsahovat predvolbu
int poradiVCisle = cisloArray.Length - 1;
for (int m = maskaArray.Length - 1; m >= 0; m--)
{

char znakZMasky = maskaArray[m];
if (char.IsDigit(znakZMasky))
pouzitelnaCisla.Add(znakZMasky.ToString());
else if (znakZMasky.ToString() == " ")
pouzitelnaCisla.Add(" ");
else if (znakZMasky.ToString() == "+")
pouzitelnaCisla.Add("+");
else if (znakZMasky.ToString() == "*")
pouzitelnaCisla.Add("*");
else if (znakZMasky.ToString() == "#")
pouzitelnaCisla.Add("#");
else if (znakZMasky.ToString() == "@")
{
if (poradiVCisle >= 0)
{
pouzitelnaCisla.Add(cisloArray[poradiVCisle].ToString());
poradiVCisle--;
}
else
{
//zbyle pozice z masky, ktere nejsou obsazeny v cisle, muzu doplnit nulami
pouzitelnaCisla.Add(0.ToString());
}
}
}

StringBuilder konecneCislo = new StringBuilder();
//todo: obracene :)
for (int i = pouzitelnaCisla.Count - 1; i >= 0; i--)
{
konecneCislo.Append(pouzitelnaCisla[i]);
}
return konecneCislo.ToString();
}
}
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

11:06:31 01.01.2013

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Hamon
{
/// <summary>
/// Ahoj,
/// mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru,
/// ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny,
/// a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)
/// Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka),
/// databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".
/// Jak toto nejlip vyresit?
/// Predem diky za tipy a pekny novy rok.
/// </summary>
class Program
{
static void Main(string[] args)
{
string mask = "+420 @@@ @@@ @@@";
{
Console.WriteLine(mask);
string[] num = new string[] { "+420 123 456 789", "+420123 456789", "123456789","12345" };
foreach (string s in num)
Console.WriteLine(Hamon1(mask, s));
foreach (string s in num)
Console.WriteLine(Hamon(mask, s));
}

Console.WriteLine("Hotovo");
Console.ReadKey();
}
static string Hamon1(string mask, string num)
{
num = Regex.Replace(num, @"[^+^0-9]+","");
num = num.Replace("+420", "");
num = num.PadLeft(9, '0');
var sb = new StringBuilder();
int i=0;
foreach (var c in mask)
{
if (c == '@')
{
sb.Append(num[i++]);
if (i >= num.Length) break;
}
else sb.Append(c);
}
return sb.ToString();
}
static string Hamon(string mask, string num)
{
//ziskani cisla bez neuzitecnych znaku
StringBuilder sb = new StringBuilder();
if (num.Trim().StartsWith("+")) sb.Append("+");

List<char> castiCisla = new List<char>();
castiCisla.AddRange(num.ToCharArray());
foreach (char c in castiCisla)
{
if (char.IsDigit(c))
{
sb.Append(c);
}
}
string pouzeCislo = sb.ToString();

//cislo bez neuzitecnych znaku na pole, protoze budu jednotlive znaky vybirat a vkladat do seznamu pouzitelnych
char[] cisloArray = pouzeCislo.ToCharArray();

//masku na pole, protoze budu kontrolovat, jestli je na aktualni pozici v masce znak nebo mezera
char[] maskaArray = mask.ToCharArray();

List<string> pouzitelnaCisla = new List<string>();
//odzadu, protoze maska nemusi obsahovat predvolbu
int poradiVCisle = cisloArray.Length - 1;
for (int m = maskaArray.Length - 1; m >= 0; m--)
{

char znakZMasky = maskaArray[m];
if (char.IsDigit(znakZMasky))
pouzitelnaCisla.Add(znakZMasky.ToString());
else if (znakZMasky.ToString() == " ")
pouzitelnaCisla.Add(" ");
else if (znakZMasky.ToString() == "+")
pouzitelnaCisla.Add("+");
else if (znakZMasky.ToString() == "*")
pouzitelnaCisla.Add("*");
else if (znakZMasky.ToString() == "#")
pouzitelnaCisla.Add("#");
else if (znakZMasky.ToString() == "@")
{
if (poradiVCisle >= 0)
{
pouzitelnaCisla.Add(cisloArray[poradiVCisle].ToString());
poradiVCisle--;
}
else
{
//zbyle pozice z masky, ktere nejsou obsazeny v cisle, muzu doplnit nulami
pouzitelnaCisla.Add(0.ToString());
}
}
}

StringBuilder konecneCislo = new StringBuilder();
//todo: obracene :)
for (int i = pouzitelnaCisla.Count - 1; i >= 0; i--)
{
konecneCislo.Append(pouzitelnaCisla[i]);
}
return konecneCislo.ToString();
}
}
}

Zdravim

TC

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: hamon ♂

19:25:59 31.12.2012

TC: diky za priklady, nechal jsem se jimi inspirovat a nakonec sesmolil nasledujici kod. Jeste to neni uplne hotove a univerzalni, ale treba se to nekomu hodi.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string mask = "+420 @@@ @@@ @@@";
{
Console.WriteLine(mask);
string[] num = new string[] { "+420 123 456 789", "+420123 456789", "123456789" };
foreach (string s in num)
Console.WriteLine(Hamon(mask, s));
}

Console.WriteLine("Hotovo");
Console.ReadKey();
}

static string Hamon(string mask, string num)
{
//ziskani cisla bez neuzitecnych znaku
StringBuilder sb = new StringBuilder();
if (num.Trim().StartsWith("+")) sb.Append("+");

List<char> castiCisla = new List<char>();
castiCisla.AddRange(num.ToCharArray());
foreach (char c in castiCisla)
{
if (char.IsDigit(c))
{
sb.Append(c);
}
}
string pouzeCislo = sb.ToString();

//cislo bez neuzitecnych znaku na pole, protoze budu jednotlive znaky vybirat a vkladat do seznamu pouzitelnych
char[] cisloArray = pouzeCislo.ToCharArray();

//masku na pole, protoze budu kontrolovat, jestli je na aktualni pozici v masce znak nebo mezera
char[] maskaArray = mask.ToCharArray();

List<string> pouzitelnaCisla = new List<string>();
//odzadu, protoze maska nemusi obsahovat predvolbu
int poradiVCisle = cisloArray.Length - 1;
for (int m = maskaArray.Length - 1; m >= 0; m--)
{

char znakZMasky = maskaArray[m];
if (char.IsDigit(znakZMasky))
pouzitelnaCisla.Add(znakZMasky.ToString());
else if (znakZMasky.ToString() == " ")
pouzitelnaCisla.Add(" ");
else if (znakZMasky.ToString() == "+")
pouzitelnaCisla.Add("+");
else if (znakZMasky.ToString() == "*")
pouzitelnaCisla.Add("*");
else if (znakZMasky.ToString() == "#")
pouzitelnaCisla.Add("#");
else if (znakZMasky.ToString() == "@")
{
if (poradiVCisle >= 0)
{
pouzitelnaCisla.Add(cisloArray[poradiVCisle].ToString());
poradiVCisle--;
}
else
{
//zbyle pozice z masky, ktere nejsou obsazeny v cisle, muzu doplnit nulami
pouzitelnaCisla.Add(0.ToString());
}
}
}

StringBuilder konecneCislo = new StringBuilder();
//todo: obracene :)
for (int i = pouzitelnaCisla.Count - 1; i >= 0; i--)
{
konecneCislo.Append(pouzitelnaCisla[i]);
}
return konecneCislo.ToString();
}
}
}

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

15:46:00 31.12.2012

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hamon
{
/// <summary>
/// Ahoj,
/// mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru,
/// ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny,
/// a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)
/// Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka),
/// databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".
/// Jak toto nejlip vyresit?
/// Predem diky za tipy a pekny novy rok.
/// </summary>
class Program
{
static void Main(string[] args)
{
foreach (var mask in new string[] { "*** *** *** ***", "**** **** kuku *" })
{
Console.WriteLine(mask);
foreach (var num in new string[] { "+420 123 456 789", "+420123 456789","123456789" })
Console.WriteLine(Hamon(mask, num));
foreach (var num in new string[] { "+420 123 456 789", "+420123 456789","123456789" })
Console.WriteLine(Hamon(mask, num,"+420","+421","+352"));
}
}
static string Hamon(string mask,string num, params string []ignore)
{
if (ignore != null)
foreach (var ign in ignore)
num = num.Replace(ign, "");
var sb = new StringBuilder();
if (num.Trim().StartsWith("+")) sb.Append("+");
int i=-1, n = mask.Length;
foreach(var c in num)
if (char.IsDigit(c))
{
for (i++; i < n && mask[i] != '*';i++ ) sb.Append(mask[i]);
sb.Append(c);
}
return sb.ToString();
}
}
}
Zdravim

TC

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

15:20:20 31.12.2012

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hamon
{
/// <summary>
/// Ahoj,
/// mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru,
/// ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny,
/// a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)
/// Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka),
/// databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".
/// Jak toto nejlip vyresit?
/// Predem diky za tipy a pekny novy rok.
/// </summary>
class Program
{
static void Main(string[] args)
{
foreach (var mask in new string[] { "*** *** *** ***", "**** **** kuku *" })
{
Console.WriteLine(mask);
foreach (var num in new string[] { "+420 123 456 789", "+420123 456789","123456789" })
Console.WriteLine(Hamon(mask, num));
}
}
static string Hamon(string mask,string num)
{
var sb = new StringBuilder();
if (num.Trim().StartsWith("+")) sb.Append("+");
int i=-1, n = mask.Length;
foreach(var c in num)
if (char.IsDigit(c))
{
for (i++; i < n && mask[i] != '*';i++ ) sb.Append(mask[i]);
sb.Append(c);
}
return sb.ToString();
}
}
}
Zdravim
TC

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

13:26:07 31.12.2012

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hamon
{
/// <summary>
/// Ahoj,
/// mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru,
/// ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny,
/// a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)
/// Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka),
/// databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".
/// Jak toto nejlip vyresit?
/// Predem diky za tipy a pekny novy rok.
/// </summary>
class Program
{
static void Main(string[] args)
{
foreach (var mask in new string[] { "*** *** *** ***", "**** **** kuku *" })
{
Console.WriteLine(mask);
foreach (var num in new string[] { "+420 123 456 789", "+420123 456789","123456789" })
Console.WriteLine(Hamon(mask, num));
}
}
static string Hamon(string mask,string num)
{
var sb = new StringBuilder();
if (num.Trim().StartsWith("+")) sb.Append("+");
int i=0, n = mask.Length;
foreach(var c in num)
if (char.IsDigit(c))
{
for (; i < n && mask[i] != '*';i++ ) sb.Append(mask[i]);
sb.Append(c);
i++;
}
return sb.ToString();
}
}
}

Zdravim

TC

Citovat příspěvek

 

Re: Preformatovani telefonniho cisla

Autor: TC ♂

13:16:59 31.12.2012

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hamon
{
/// <summary>
/// Ahoj,
/// mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru,
/// ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny,
/// a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)
/// Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka),
/// databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".
/// Jak toto nejlip vyresit?
/// Predem diky za tipy a pekny novy rok.
/// </summary>
class Program
{
static void Main(string[] args)
{
foreach (var mask in new string[] { "*** *** *** ***", "**** **** *" })
{
Console.WriteLine(mask);
foreach (var num in new string[] { "+420 123 456 789", "+420123 456789","123456789" })
Console.WriteLine(Hamon(mask, num));
}
}
static string Hamon(string mask,string num)
{
var sb = new StringBuilder();
if (num.Trim().StartsWith("+")) sb.Append("+");
int i=0, n = mask.Length;
foreach(var c in num)
if (char.IsDigit(c))
{
if (i < n && mask[i] != '*') sb.Append(' ');
sb.Append(c);
i++;
}
return sb.ToString();
}
}
}

Zdravim

TC

Citovat příspěvek

 

Preformatovani telefonniho cisla

Autor: hamon ♂

9:07:49 31.12.2012

Ahoj,
mam telefonni cislo v nejakem tvaru, ktery neznam. Potrebuju toto cislo naformatovat do pozadovaneho tvaru, ktery si zvoli uzivatel. Telefonni cisla taham z nekolika databazi, proto muze byt zdrojovy tvar ruzny, a zobrazuji je v aplikaci. Samozrejme neni mozne cisla upravovat rucne :)

Priklad: databaze A obsahuje telefonni cisla ve tvaru "ABCDE FGHI" (oddelene posledni ctyrcisli jako linka), databaze B zase "+420 ABCDEFGHI" a uzivatel je chce zobrazit podle masky "ABC DEF GHI".

Jak toto nejlip vyresit?
Predem diky za tipy a pekny novy rok.

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: