1 public class StringControl 2 { 3 4 /// <summary> 5 /// 客户端浏览器 6 /// http://en.wikipedia.org/wiki/Web_browser 7 /// http://www.w3schools.com/browsers/browsers_stats.asp 8 /// The major web browsers are Google Chrome, Mozilla Firefox, Internet Explorer, Opera, and Safari. 9 /// 涂聚文 20130806 10 /// </summary> 11 /// <param name="strClient">客户端环境</param> 12 /// <param name="ver">浏览器版</param> 13 /// <returns>返回浏览器名称</returns> 14 public string getBrowser(string strClient, out string ver) 15 { 16 string strBrowser = null; 17 if (strClient.Contains("MSIE") == true) 18 { 19 strBrowser = "Internet Explorer"; 20 ver = getIEVer(strClient); 21 } 22 else if (strClient.Contains("Opera") == true) 23 { 24 strBrowser = "Opera"; 25 ver = getBrowserVer(strClient, "Version"); 26 } 27 else if ((strClient.Contains("Firefox") == true) && (strClient.Contains("Chrome") == false) && (strClient.Contains("Safari") == false) && (strClient.Contains("Navigator") == false)) 28 { 29 strBrowser = "FireFox"; 30 ver = getBrowserVer(strClient, "Firefox"); 31 32 } 33 else if ((strClient.Contains("AppleWebKit") == true) && (strClient.Contains("Chrome") == true) && (strClient.Contains("Safari") == true) && (strClient.Contains("Flock") == false)) 34 { 35 strBrowser = "Google Chrome"; 36 ver = getBrowserVer(strClient, "Chrome"); 37 } 38 else if ((strClient.Contains("Firefox") == true) && (strClient.Contains("Chrome") == false) && (strClient.Contains("Safari") == false) && (strClient.Contains("Navigator") == true)) 39 { 40 strBrowser = "Netscape Navigator"; 41 ver = getBrowserVer(strClient, "Navigator"); 42 } 43 else if ((strClient.Contains("AppleWebKit") == true) && (strClient.Contains("Flock") == true) && (strClient.Contains("Chrome") == true) && (strClient.Contains("Safari") == true)) 44 { 45 strBrowser = "Flock"; 46 ver = getBrowserVer(strClient, "Flock"); 47 } 48 else if ((strClient.Contains("AppleWebKit") == true) && (strClient.Contains("Chrome") == false) && (strClient.Contains("Safari") == true)) 49 { 50 strBrowser = "Safari"; 51 ver = getBrowserVer(strClient, "Version"); 52 } 53 else 54 { 55 strBrowser = "NoData"; 56 ver = "NoData"; 57 } 58 return strBrowser; 59 } 60 /// <summary> 61 /// 客户端操作系统 62 /// http://en.wikipedia.org/wiki/Windows_NT 63 /// 64 /// </summary> 65 /// <param name="strClient">客户端环境</param> 66 /// <returns>返回操作系统名称</returns> 67 public string getPlatform(string strClient) 68 { 69 string OpertorSystem = String.Empty; 70 strClient = strClient.ToLower(); 71 72 if (strClient.Contains("mac") == true) 73 { 74 return OpertorSystem = "Mac"; 75 } 76 else if (strClient.Contains("unix") == true) 77 { 78 return OpertorSystem = "Unix"; 79 } 80 else if (strClient.Contains("linux") == true) 81 { 82 return OpertorSystem = "Linux"; 83 } 84 else if (strClient.Contains("sunos") == true) 85 { 86 return OpertorSystem = "SunOS"; 87 } 88 else if (strClient.Contains("android") == true) 89 { 90 return OpertorSystem = "Android"; 91 } 92 else if (strClient.Contains("ipad") == true) 93 { 94 return OpertorSystem = "iPAD"; 95 } 96 else if (strClient.Contains("iphone") == true) 97 { 98 return OpertorSystem = "iPhone"; 99 } 100 else if (strClient.Contains("windows ce") == true) 101 { 102 return OpertorSystem = "Windows CE"; 103 } 104 else if (strClient.Contains("windows phone") == true) 105 { 106 return OpertorSystem = "Windows Phone"; 107 } 108 else if (strClient.Contains("symbian") == true) 109 { 110 return OpertorSystem = "symbian"; 111 } 112 else if (strClient.Contains("htc") == true) 113 { 114 return OpertorSystem = "HTC"; 115 } 116 else if (strClient.Contains("samsung") == true) 117 { 118 return OpertorSystem = "samsung"; 119 } 120 else if (strClient.Contains("blackberry") == true) 121 { 122 return OpertorSystem = "blackberry"; 123 } 124 else if (strClient.Contains("nokia") == true) 125 { 126 return OpertorSystem = "nokia"; 127 } 128 else if (strClient.Contains("huawei") == true) 129 { 130 return OpertorSystem = "HuaWei"; 131 } 132 else if (strClient.Contains("xiaomi") == true) 133 { 134 return OpertorSystem = "XiaoMi"; 135 } 136 else if (strClient.Contains("Windows NT 3.1") == true) 137 { 138 return OpertorSystem = "Windows NT 3.1"; 139 } 140 else if (strClient.Contains("Windows NT 3.5") == true) 141 { 142 return OpertorSystem = "Windows NT 3.5"; 143 } 144 else if (strClient.Contains("Windows NT 3.51") == true) 145 { 146 return OpertorSystem = "Windows NT 3.51"; 147 } 148 else if (strClient.Contains("Windows NT 4.0") == true) 149 { 150 return OpertorSystem = "Windows NT 4.0"; 151 } 152 else if (strClient.Contains("95") == true) 153 { 154 return OpertorSystem = "Windows 95"; 155 } 156 else if (strClient.Contains("Me") == true) 157 { 158 return OpertorSystem = "Windows Me"; 159 } 160 else if (strClient.Contains("98") == true) 161 { 162 return OpertorSystem = "Windows 98"; 163 } 164 else if (strClient.Contains("Windows NT 5.0") == true) 165 { 166 return OpertorSystem = "Windows 2000"; 167 } 168 else if (strClient.Contains("Windows NT 5.1") == true) 169 { 170 return OpertorSystem = "Windows XP/Windows Fundamentals"; 171 } 172 else if (strClient.Contains("Windows NT 5.2") == true) 173 { 174 return OpertorSystem = "Windows Server 2003/Windows Home Server"; 175 } 176 else if (strClient.Contains("Windows NT 6.0") == true) 177 { 178 return OpertorSystem = "Windows Vista/Windows Server 2008"; 179 } 180 181 else if (strClient.Contains("Windows NT 6.1") == true) 182 { 183 return OpertorSystem = "Windows 7/ Windows Server 2008 R2"; 184 } 185 else if (strClient.Contains("Windows NT 6.2") == true) 186 { 187 return OpertorSystem = "Windows 8/Windows Phone 8/Windows Server 2012"; 188 } 189 else if (strClient.Contains("Windows NT 6.3") == true) 190 { 191 return OpertorSystem = "Windows 8.1"; 192 } 193 194 else 195 { 196 return OpertorSystem = "NoData"; 197 } 198 //OpertorSystem; 199 } 200 /// <summary> 201 /// IE 202 /// </summary> 203 /// <param name="strClient"></param> 204 /// <returns></returns> 205 private string getIEVer(string strClient) 206 { 207 string ver = string.Empty; 208 209 if (strClient.Contains("MSIE 10.0") == true) 210 { 211 return ver = "10.0"; 212 } 213 if (strClient.Contains("MSIE 9.0") == true) 214 { 215 return ver = "9.0"; 216 } 217 if (strClient.Contains("MSIE 8.0") == true) 218 { 219 return ver = "8.0"; 220 } 221 else if (strClient.Contains("MSIE 7.0") == true) 222 { 223 return ver = "7.0"; 224 } 225 else if (strClient.Contains("MSIE 6.0") == true) 226 { 227 return ver = "6.0"; 228 } 229 else if (strClient.Contains("MSIE 5.0") == true) 230 { 231 return ver = "5.0"; 232 } 233 else 234 { 235 return ver = "1.0"; 236 } 237 238 } 239 /// <summary> 240 /// 得到版本 241 /// </summary> 242 /// <param name="strClient">客户端环境</param> 243 /// <param name="browere">浏览器名称</param> 244 /// <returns>返回版本号</returns> 245 private string getBrowserVer(string strClient, string browere) 246 { 247 string ver = string.Empty; 248 string[] words = strClient.Split(' '); 249 string browsername = string.Empty; 250 foreach (string word in words) 251 { 252 if (word.Contains(browere) == true) 253 { 254 browsername = word; 255 } 256 //Response.Write(word + "<br/>"); 257 } 258 //Response.Write("浏览器名称及版本:" + browsername + "<br>"); 259 string strnamd = ""; 260 //string strver = ""; 261 string[] wd = browsername.Split('/'); 262 foreach (string nd in wd) 263 { 264 if (nd.Contains(browere) == true) 265 { 266 strnamd = nd; 267 } 268 else 269 { 270 ver = nd; 271 } 272 } 273 return ver; 274 } 275 /// <summary> 276 /// 浏览器语言 277 /// http://msdn.microsoft.com/en-us/library/ms533052(VS.85).aspx 278 /// http://www.w3schools.com/tags/ref_language_codes.asp 279 /// http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes 280 /// http://www.metamodpro.com/browser-language-codes 281 /// http://4umi.com/web/html/languagecodes.php 282 /// </summary> 283 /// <param name="strClicent">客户端环境</param> 284 /// <returns>返回浏览语言</returns> 285 public string getBrowserLanguage(string strClicent) 286 { 287 //zh-tw Chinese (Taiwan) zh-cn Chinese (PRC) 288 //zh-hk Chinese (Hong Kong SAR) zh-sg Chinese (Singapore) 289 290 string BroswerLanguage = string.Empty; 291 strClicent = strClicent.ToLower(); 292 switch (strClicent) 293 { 294 case "zh-cn": 295 BroswerLanguage = "zh-cn";//Chinese (PRC) 296 break; 297 case "zh-tw": 298 BroswerLanguage = "zh-tw";//Chinese (Taiwan) 299 break; 300 case "zh-hk": 301 BroswerLanguage = "zh-hk";//Chinese (Hong Kong SAR) 302 break; 303 case "zh-sg": 304 BroswerLanguage = "zh-sg";//Chinese (Singapore) 305 break; 306 case "af": 307 BroswerLanguage = "af";//Afrikaans 308 break; 309 case "sq": 310 BroswerLanguage = "sq";//Albanian 311 break; 312 case "ar-sa": 313 BroswerLanguage = "";//Arabic (Saudi Arabia) 314 break; 315 case "ar-iq": 316 BroswerLanguage = "ar-iq";//Arabic (Iraq) 317 break; 318 case "ar-eg": 319 BroswerLanguage = "ar-eg";//Arabic (Egypt) 320 break; 321 case "ar-ly": 322 BroswerLanguage = "ar-ly";//Arabic (Libya) 323 break; 324 case "ar-dz": 325 BroswerLanguage = "ar-dz";//Arabic (Algeria) 326 break; 327 case "ar-ma": 328 BroswerLanguage = "ar-ma";//Arabic (Morocco) 329 break; 330 case "ar-tn": 331 BroswerLanguage = "ar-tn";//Arabic (Tunisia) 332 break; 333 case "ar-om": 334 BroswerLanguage = "ar-om";//Arabic (Oman) 335 break; 336 case "ar-ye": 337 BroswerLanguage = "ar-ye";//Arabic (Yemen) 338 break; 339 case "ar-sy": 340 BroswerLanguage = "ar-sy";//Arabic (Syria) 341 break; 342 case "ar-jo": 343 BroswerLanguage = "ar-jo";//Arabic (Jordan) 344 break; 345 case "ar-lb": 346 BroswerLanguage = "ar-lb";//Arabic (Lebanon) 347 break; 348 case "ar-kw": 349 BroswerLanguage = "ar-kw";//Arabic (Kuwait) 350 break; 351 case "ar-ae": 352 BroswerLanguage = "ar-ae";//Arabic (U.A.E.) 353 break; 354 case "ar-bh": 355 BroswerLanguage = "ar-bh";//Arabic (Bahrain) 356 break; 357 case "ar-qa": 358 BroswerLanguage = "ar-qa";//Arabic (Qatar) 359 break; 360 case "eu": 361 BroswerLanguage = "Basque";// 362 break; 363 case "bg": 364 BroswerLanguage = "bg";// Bulgarian 365 break; 366 case "be": 367 BroswerLanguage = "be";//Belarusian 368 break; 369 case "ca": 370 BroswerLanguage = "ca";//Catalan 371 break; 372 case "hr": 373 BroswerLanguage = "hr";//Croatian 374 break; 375 case "cs": 376 BroswerLanguage = "cs";//Czech 377 break; 378 case "da": 379 BroswerLanguage = "da";// Danish 380 break; 381 case "nl": 382 BroswerLanguage = "nl";//Dutch (Standard) 383 break; 384 case "nl-be": 385 BroswerLanguage = "nl-be";// Dutch (Belgium) 386 break; 387 case "en": 388 BroswerLanguage = "en";// English 389 break; 390 case "en-us": 391 BroswerLanguage = "en-us";// English (United States) 392 break; 393 case "en-gb": 394 BroswerLanguage = "en-gb";//English (United Kingdom) 395 break; 396 case "en-au": 397 BroswerLanguage = "en-au";// English (Australia) 398 break; 399 case "en-ca": 400 BroswerLanguage = "en-ca";// English (Canada) 401 break; 402 case "en-nz": 403 BroswerLanguage = "en-nz";// English (New Zealand) 404 break; 405 case "en-ie": 406 BroswerLanguage = "en-ie";// English (Ireland) 407 break; 408 case "en-za": 409 BroswerLanguage = "en-za";// English (South Africa) 410 break; 411 case "en-jm": 412 BroswerLanguage = "en-jm";// English (Jamaica) 413 break; 414 //case "en": 415 // BroswerLanguage = "en";// English (Caribbean) 416 // break; 417 case "en-bz": 418 BroswerLanguage = "en-bz";// English (Belize) 419 break; 420 case "en-tt": 421 BroswerLanguage = "en-tt";// English (Trinidad) 422 break; 423 case "et": 424 BroswerLanguage = "et";// Estonian 425 break; 426 case "fo": 427 BroswerLanguage = "fo";// Faeroese 428 break; 429 case "fa": 430 BroswerLanguage = "fa";// Farsi 431 break; 432 case "fi": 433 BroswerLanguage = "fi";// Finnish 434 break; 435 case "fr": 436 BroswerLanguage = "fr";// French (Standard) 437 break; 438 case "fr-be": 439 BroswerLanguage = "fr-be";// French (Belgium) 440 break; 441 case "fr-ca": 442 BroswerLanguage = "fr-ca";// French (Canada) 443 break; 444 case "fr-ch": 445 BroswerLanguage = "fr-ch";// French (Switzerland) 446 break; 447 case "fr-lu": 448 BroswerLanguage = "fr-lu";// French (Luxembourg) 449 break; 450 case "gd": 451 BroswerLanguage = "";// Gaelic (Scotland) 452 break; 453 case "gd-ie": 454 BroswerLanguage = "";// Gaelic (Ireland) 455 break; 456 case "de": 457 BroswerLanguage = "";// German (Standard) 458 break; 459 case "de-ch": 460 BroswerLanguage = "";// German (Switzerland) 461 break; 462 case "de-at": 463 BroswerLanguage = "";// German (Austria) 464 break; 465 case "de-lu": 466 BroswerLanguage = "";// German (Luxembourg) 467 break; 468 case "de-li": 469 BroswerLanguage = "";// German (Liechtenstein) 470 break; 471 case "el": 472 BroswerLanguage = "el";// Greek 473 break; 474 case "he": 475 BroswerLanguage = "he";// Hebrew 476 break; 477 case "hi": 478 BroswerLanguage = "hi";// Hindi 479 break; 480 case "hu": 481 BroswerLanguage = "hu";// Hungarian 482 break; 483 case "is": 484 BroswerLanguage = "is";// Icelandic 485 break; 486 case "id": 487 BroswerLanguage = "id";// Indonesian 488 break; 489 case "it": 490 BroswerLanguage = "it";// Italian (Standard) 491 break; 492 case "it-ch": 493 BroswerLanguage = "it-ch";// Italian (Switzerland) 494 break; 495 case "ja": 496 BroswerLanguage = "ja";// Japanese 497 break; 498 case "ko": 499 BroswerLanguage = "ko";// Korean /Korean (Johab) 500 break; 501 //case "ko": 502 // BroswerLanguage = "ko";// Korean (Johab) 503 // break; 504 case "lv": 505 BroswerLanguage = "lv";// Latvian 506 break; 507 case "lt": 508 BroswerLanguage = "lt";//Lithuanian 509 break; 510 case "mk": 511 BroswerLanguage = "mk";// FYRO Macedonian ms Malaysian 512 break; 513 case "mt": 514 BroswerLanguage = "mt";// Maltese 515 break; 516 case "no": 517 BroswerLanguage = "no";// Norwegian (Bokmal) 518 break; 519 //case "no": 520 // BroswerLanguage = "no";// Norwegian (Nynorsk) 521 // break; 522 case "pl": 523 BroswerLanguage = "pl";// Polish 524 break; 525 case "pt-br": 526 BroswerLanguage = "pt-br";// Portuguese (Brazil) 527 break; 528 case "pt": 529 BroswerLanguage = "pt";// Portuguese (Portugal) 530 break; 531 case "rm": 532 BroswerLanguage = "rm";// Rhaeto-Romanic 533 break; 534 case "ro": 535 BroswerLanguage = "ro";// Romanian 536 break; 537 case "ro-mo": 538 BroswerLanguage = "ro-mo";// Romanian (Moldavia) 539 break; 540 case "ru": 541 BroswerLanguage = "ru";// Russian 542 break; 543 case "ru-mo": 544 BroswerLanguage = "ru-mo";// Russian (Moldavia) 545 break; 546 case "sz": 547 BroswerLanguage = "sz";// Sami (Lappish) 548 break; 549 case "sr": 550 BroswerLanguage = "sr";// Serbian (Cyrillic) 551 break; 552 //case "sr": 553 // BroswerLanguage = "sr";// Serbian (Latin) 554 // break; 555 case "sk": 556 BroswerLanguage = "sk";// Slovak 557 break; 558 case "sl": 559 BroswerLanguage = "sl";// Slovenian 560 break; 561 case "sb": 562 BroswerLanguage = "sb";// Sorbian 563 break; 564 case "es": 565 BroswerLanguage = "es";// Spanish (Spain, traditional) 566 break; 567 //case "es": 568 // BroswerLanguage = "es";// Spanish (Spain, modern) 569 // break; 570 case "es-ar": 571 BroswerLanguage = "es-ar";// Spanish (Argentina) 572 break; 573 case "es-gt": 574 BroswerLanguage = "es-gt";// Spanish (Guatemala) 575 break; 576 case "es-cr": 577 BroswerLanguage = "es-cr";//Spanish (Costa Rica) 578 break; 579 case "es-pa": 580 BroswerLanguage = "es-pa";// Spanish (Panama) 581 break; 582 case "es-do": 583 BroswerLanguage = "es-do";// Spanish (Dominican Republic) 584 break; 585 case "es-mx": 586 BroswerLanguage = "es-mx";// Spanish (Mexico) 587 break; 588 case "es-ve": 589 BroswerLanguage = "es-ve";//Spanish (Venezuela) 590 break; 591 case "es-co": 592 BroswerLanguage = "es-co";// Spanish (Colombia) 593 break; 594 case "es-pe": 595 BroswerLanguage = "es-pe";// Spanish (Peru) 596 break; 597 case "es-ec": 598 BroswerLanguage = "es-ec";// Spanish (Ecuador) 599 break; 600 case "es-cl": 601 BroswerLanguage = "es-cl";// Spanish (Chile) 602 break; 603 case "es-uy": 604 BroswerLanguage = "es-uy";// Spanish (Uruguay) 605 break; 606 case "es-py": 607 BroswerLanguage = "es-py";// Spanish (Paraguay) 608 break; 609 case "es-bo": 610 BroswerLanguage = "es-bo";// Spanish (Bolivia) 611 break; 612 case "es-sv": 613 BroswerLanguage = "es-sv";// Spanish (El Salvador) 614 break; 615 case "es-hn": 616 BroswerLanguage = "es-hn";// Spanish (Honduras) 617 break; 618 case "es-ni": 619 BroswerLanguage = "es-ni";// Spanish (Nicaragua) 620 break; 621 case "es-pr": 622 BroswerLanguage = "es-pr";// Spanish (Puerto Rico) 623 break; 624 case "sx": 625 BroswerLanguage = "sx";// Sutu 626 break; 627 case "sv": 628 BroswerLanguage = "sv";// Swedish 629 break; 630 case "sv-fi": 631 BroswerLanguage = "sv-fi";// Swedish (Finland) 632 break; 633 case "th": 634 BroswerLanguage = "th";// Thai 635 break; 636 case "ts": 637 BroswerLanguage = "";// Tsonga 638 break; 639 case "tn": 640 BroswerLanguage = "tn";// Tswana 641 break; 642 case "tr": 643 BroswerLanguage = "tr";// Turkish 644 break; 645 case "uk": 646 BroswerLanguage = "uk";// Ukrainian 647 break; 648 case "ur": 649 BroswerLanguage = "ur";// Urdu 650 break; 651 case "ve": 652 BroswerLanguage = "ve";// Venda 653 break; 654 case "vi": 655 BroswerLanguage = "vi";// Vietnamese 656 break; 657 case "xh": 658 BroswerLanguage = "xh";// Xhosa 659 break; 660 case "ji": 661 BroswerLanguage = "ji";// Yiddish 662 break; 663 case "zu": 664 BroswerLanguage = "zu";//Zulu 665 break; 666 // case "": 667 // BroswerLanguage = "";// 668 // break; 669 //case "": 670 // BroswerLanguage = "";// 671 // break; 672 default: 673 BroswerLanguage = "NoData"; 674 break; 675 } 676 return BroswerLanguage; 677 678 //if (strClicent.Contains("zh-cn") == true) 679 //{ 680 // return BroswerLanguage = "zh-cn"; 681 //} 682 //if (strClicent.Contains("zh-tw") == true) 683 //{ 684 // return BroswerLanguage = "zh-tw"; 685 //} 686 //if (strClicent.Contains("zh-hk") == true) 687 //{ 688 // return BroswerLanguage = "zh-hk"; 689 //} 690 //if (strClicent.Contains("zh-sg") == true) 691 //{ 692 // return BroswerLanguage = "zh-sg"; 693 //} 694 //else if (strClicent.Contains("en-us") == true) 695 //{ 696 // return BroswerLanguage = "en-us"; 697 //} 698 //else 699 //{ 700 // return BroswerLanguage = "NoData"; 701 //} 702 703 } 704 }