public class StringControl { /// <summary> /// 客户端浏览器 /// http://en.wikipedia.org/wiki/Web_browser /// http://www.w3schools.com/browsers/browsers_stats.asp /// The major web browsers are Google Chrome, Mozilla Firefox, Internet Explorer, Opera, and Safari. /// 涂聚文 20130806 /// </summary> /// <param name="strClient">客户端环境</param> /// <param name="ver">浏览器版</param> /// <returns>返回浏览器名称</returns> public string getBrowser(string strClient, out string ver) { string strBrowser = null; if (strClient.Contains("MSIE") == true) { strBrowser = "Internet Explorer"; ver = getIEVer(strClient); } else if (strClient.Contains("Opera") == true) { strBrowser = "Opera"; ver = getBrowserVer(strClient, "Version"); } else if ((strClient.Contains("Firefox") == true) && (strClient.Contains("Chrome") == false) && (strClient.Contains("Safari") == false) && (strClient.Contains("Navigator") == false)) { strBrowser = "FireFox"; ver = getBrowserVer(strClient, "Firefox"); } else if ((strClient.Contains("AppleWebKit") == true) && (strClient.Contains("Chrome") == true) && (strClient.Contains("Safari") == true) && (strClient.Contains("Flock") == false)) { strBrowser = "Google Chrome"; ver = getBrowserVer(strClient, "Chrome"); } else if ((strClient.Contains("Firefox") == true) && (strClient.Contains("Chrome") == false) && (strClient.Contains("Safari") == false) && (strClient.Contains("Navigator") == true)) { strBrowser = "Netscape Navigator"; ver = getBrowserVer(strClient, "Navigator"); } else if ((strClient.Contains("AppleWebKit") == true) && (strClient.Contains("Flock") == true) && (strClient.Contains("Chrome") == true) && (strClient.Contains("Safari") == true)) { strBrowser = "Flock"; ver = getBrowserVer(strClient, "Flock"); } else if ((strClient.Contains("AppleWebKit") == true) && (strClient.Contains("Chrome") == false) && (strClient.Contains("Safari") == true)) { strBrowser = "Safari"; ver = getBrowserVer(strClient, "Version"); } else { strBrowser = "NoData"; ver = "NoData"; } return strBrowser; } /// <summary> /// 客户端操作系统 /// http://en.wikipedia.org/wiki/Windows_NT /// /// </summary> /// <param name="strClient">客户端环境</param> /// <returns>返回操作系统名称</returns> public string getPlatform(string strClient) { string OpertorSystem = String.Empty; strClient = strClient.ToLower(); if (strClient.Contains("mac") == true) { return OpertorSystem = "Mac"; } else if (strClient.Contains("unix") == true) { return OpertorSystem = "Unix"; } else if (strClient.Contains("linux") == true) { return OpertorSystem = "Linux"; } else if (strClient.Contains("sunos") == true) { return OpertorSystem = "SunOS"; } else if (strClient.Contains("android") == true) { return OpertorSystem = "Android"; } else if (strClient.Contains("ipad") == true) { return OpertorSystem = "iPAD"; } else if (strClient.Contains("iphone") == true) { return OpertorSystem = "iPhone"; } else if (strClient.Contains("windows ce") == true) { return OpertorSystem = "Windows CE"; } else if (strClient.Contains("windows phone") == true) { return OpertorSystem = "Windows Phone"; } else if (strClient.Contains("symbian") == true) { return OpertorSystem = "symbian"; } else if (strClient.Contains("htc") == true) { return OpertorSystem = "HTC"; } else if (strClient.Contains("samsung") == true) { return OpertorSystem = "samsung"; } else if (strClient.Contains("blackberry") == true) { return OpertorSystem = "blackberry"; } else if (strClient.Contains("nokia") == true) { return OpertorSystem = "nokia"; } else if (strClient.Contains("huawei") == true) { return OpertorSystem = "HuaWei"; } else if (strClient.Contains("xiaomi") == true) { return OpertorSystem = "XiaoMi"; } else if (strClient.Contains("Windows NT 3.1") == true) { return OpertorSystem = "Windows NT 3.1"; } else if (strClient.Contains("Windows NT 3.5") == true) { return OpertorSystem = "Windows NT 3.5"; } else if (strClient.Contains("Windows NT 3.51") == true) { return OpertorSystem = "Windows NT 3.51"; } else if (strClient.Contains("Windows NT 4.0") == true) { return OpertorSystem = "Windows NT 4.0"; } else if (strClient.Contains("95") == true) { return OpertorSystem = "Windows 95"; } else if (strClient.Contains("Me") == true) { return OpertorSystem = "Windows Me"; } else if (strClient.Contains("98") == true) { return OpertorSystem = "Windows 98"; } else if (strClient.Contains("Windows NT 5.0") == true) { return OpertorSystem = "Windows 2000"; } else if (strClient.Contains("Windows NT 5.1") == true) { return OpertorSystem = "Windows XP/Windows Fundamentals"; } else if (strClient.Contains("Windows NT 5.2") == true) { return OpertorSystem = "Windows Server 2003/Windows Home Server"; } else if (strClient.Contains("Windows NT 6.0") == true) { return OpertorSystem = "Windows Vista/Windows Server 2008"; } else if (strClient.Contains("Windows NT 6.1") == true) { return OpertorSystem = "Windows 7/ Windows Server 2008 R2"; } else if (strClient.Contains("Windows NT 6.2") == true) { return OpertorSystem = "Windows 8/Windows Phone 8/Windows Server 2012"; } else if (strClient.Contains("Windows NT 6.3") == true) { return OpertorSystem = "Windows 8.1"; } else { return OpertorSystem = "NoData"; } //OpertorSystem; } /// <summary> /// IE /// </summary> /// <param name="strClient"></param> /// <returns></returns> private string getIEVer(string strClient) { string ver = string.Empty; if (strClient.Contains("MSIE 10.0") == true) { return ver = "10.0"; } if (strClient.Contains("MSIE 9.0") == true) { return ver = "9.0"; } if (strClient.Contains("MSIE 8.0") == true) { return ver = "8.0"; } else if (strClient.Contains("MSIE 7.0") == true) { return ver = "7.0"; } else if (strClient.Contains("MSIE 6.0") == true) { return ver = "6.0"; } else if (strClient.Contains("MSIE 5.0") == true) { return ver = "5.0"; } else { return ver = "1.0"; } } /// <summary> /// 得到版本 /// </summary> /// <param name="strClient">客户端环境</param> /// <param name="browere">浏览器名称</param> /// <returns>返回版本号</returns> private string getBrowserVer(string strClient, string browere) { string ver = string.Empty; string[] words = strClient.Split(' '); string browsername = string.Empty; foreach (string word in words) { if (word.Contains(browere) == true) { browsername = word; } //Response.Write(word + "<br/>"); } //Response.Write("浏览器名称及版本:" + browsername + "<br>"); string strnamd = ""; //string strver = ""; string[] wd = browsername.Split('/'); foreach (string nd in wd) { if (nd.Contains(browere) == true) { strnamd = nd; } else { ver = nd; } } return ver; } /// <summary> /// 浏览器语言 /// http://msdn.microsoft.com/en-us/library/ms533052(VS.85).aspx /// http://www.w3schools.com/tags/ref_language_codes.asp /// http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes /// http://www.metamodpro.com/browser-language-codes /// http://4umi.com/web/html/languagecodes.php /// </summary> /// <param name="strClicent">客户端环境</param> /// <returns>返回浏览语言</returns> public string getBrowserLanguage(string strClicent) { //zh-tw Chinese (Taiwan) zh-cn Chinese (PRC) //zh-hk Chinese (Hong Kong SAR) zh-sg Chinese (Singapore) string BroswerLanguage = string.Empty; strClicent = strClicent.ToLower(); switch (strClicent) { case "zh-cn": BroswerLanguage = "zh-cn";//Chinese (PRC) break; case "zh-tw": BroswerLanguage = "zh-tw";//Chinese (Taiwan) break; case "zh-hk": BroswerLanguage = "zh-hk";//Chinese (Hong Kong SAR) break; case "zh-sg": BroswerLanguage = "zh-sg";//Chinese (Singapore) break; case "af": BroswerLanguage = "af";//Afrikaans break; case "sq": BroswerLanguage = "sq";//Albanian break; case "ar-sa": BroswerLanguage = "";//Arabic (Saudi Arabia) break; case "ar-iq": BroswerLanguage = "ar-iq";//Arabic (Iraq) break; case "ar-eg": BroswerLanguage = "ar-eg";//Arabic (Egypt) break; case "ar-ly": BroswerLanguage = "ar-ly";//Arabic (Libya) break; case "ar-dz": BroswerLanguage = "ar-dz";//Arabic (Algeria) break; case "ar-ma": BroswerLanguage = "ar-ma";//Arabic (Morocco) break; case "ar-tn": BroswerLanguage = "ar-tn";//Arabic (Tunisia) break; case "ar-om": BroswerLanguage = "ar-om";//Arabic (Oman) break; case "ar-ye": BroswerLanguage = "ar-ye";//Arabic (Yemen) break; case "ar-sy": BroswerLanguage = "ar-sy";//Arabic (Syria) break; case "ar-jo": BroswerLanguage = "ar-jo";//Arabic (Jordan) break; case "ar-lb": BroswerLanguage = "ar-lb";//Arabic (Lebanon) break; case "ar-kw": BroswerLanguage = "ar-kw";//Arabic (Kuwait) break; case "ar-ae": BroswerLanguage = "ar-ae";//Arabic (U.A.E.) break; case "ar-bh": BroswerLanguage = "ar-bh";//Arabic (Bahrain) break; case "ar-qa": BroswerLanguage = "ar-qa";//Arabic (Qatar) break; case "eu": BroswerLanguage = "Basque";// break; case "bg": BroswerLanguage = "bg";// Bulgarian break; case "be": BroswerLanguage = "be";//Belarusian break; case "ca": BroswerLanguage = "ca";//Catalan break; case "hr": BroswerLanguage = "hr";//Croatian break; case "cs": BroswerLanguage = "cs";//Czech break; case "da": BroswerLanguage = "da";// Danish break; case "nl": BroswerLanguage = "nl";//Dutch (Standard) break; case "nl-be": BroswerLanguage = "nl-be";// Dutch (Belgium) break; case "en": BroswerLanguage = "en";// English break; case "en-us": BroswerLanguage = "en-us";// English (United States) break; case "en-gb": BroswerLanguage = "en-gb";//English (United Kingdom) break; case "en-au": BroswerLanguage = "en-au";// English (Australia) break; case "en-ca": BroswerLanguage = "en-ca";// English (Canada) break; case "en-nz": BroswerLanguage = "en-nz";// English (New Zealand) break; case "en-ie": BroswerLanguage = "en-ie";// English (Ireland) break; case "en-za": BroswerLanguage = "en-za";// English (South Africa) break; case "en-jm": BroswerLanguage = "en-jm";// English (Jamaica) break; //case "en": // BroswerLanguage = "en";// English (Caribbean) // break; case "en-bz": BroswerLanguage = "en-bz";// English (Belize) break; case "en-tt": BroswerLanguage = "en-tt";// English (Trinidad) break; case "et": BroswerLanguage = "et";// Estonian break; case "fo": BroswerLanguage = "fo";// Faeroese break; case "fa": BroswerLanguage = "fa";// Farsi break; case "fi": BroswerLanguage = "fi";// Finnish break; case "fr": BroswerLanguage = "fr";// French (Standard) break; case "fr-be": BroswerLanguage = "fr-be";// French (Belgium) break; case "fr-ca": BroswerLanguage = "fr-ca";// French (Canada) break; case "fr-ch": BroswerLanguage = "fr-ch";// French (Switzerland) break; case "fr-lu": BroswerLanguage = "fr-lu";// French (Luxembourg) break; case "gd": BroswerLanguage = "";// Gaelic (Scotland) break; case "gd-ie": BroswerLanguage = "";// Gaelic (Ireland) break; case "de": BroswerLanguage = "";// German (Standard) break; case "de-ch": BroswerLanguage = "";// German (Switzerland) break; case "de-at": BroswerLanguage = "";// German (Austria) break; case "de-lu": BroswerLanguage = "";// German (Luxembourg) break; case "de-li": BroswerLanguage = "";// German (Liechtenstein) break; case "el": BroswerLanguage = "el";// Greek break; case "he": BroswerLanguage = "he";// Hebrew break; case "hi": BroswerLanguage = "hi";// Hindi break; case "hu": BroswerLanguage = "hu";// Hungarian break; case "is": BroswerLanguage = "is";// Icelandic break; case "id": BroswerLanguage = "id";// Indonesian break; case "it": BroswerLanguage = "it";// Italian (Standard) break; case "it-ch": BroswerLanguage = "it-ch";// Italian (Switzerland) break; case "ja": BroswerLanguage = "ja";// Japanese break; case "ko": BroswerLanguage = "ko";// Korean /Korean (Johab) break; //case "ko": // BroswerLanguage = "ko";// Korean (Johab) // break; case "lv": BroswerLanguage = "lv";// Latvian break; case "lt": BroswerLanguage = "lt";//Lithuanian break; case "mk": BroswerLanguage = "mk";// FYRO Macedonian ms Malaysian break; case "mt": BroswerLanguage = "mt";// Maltese break; case "no": BroswerLanguage = "no";// Norwegian (Bokmal) break; //case "no": // BroswerLanguage = "no";// Norwegian (Nynorsk) // break; case "pl": BroswerLanguage = "pl";// Polish break; case "pt-br": BroswerLanguage = "pt-br";// Portuguese (Brazil) break; case "pt": BroswerLanguage = "pt";// Portuguese (Portugal) break; case "rm": BroswerLanguage = "rm";// Rhaeto-Romanic break; case "ro": BroswerLanguage = "ro";// Romanian break; case "ro-mo": BroswerLanguage = "ro-mo";// Romanian (Moldavia) break; case "ru": BroswerLanguage = "ru";// Russian break; case "ru-mo": BroswerLanguage = "ru-mo";// Russian (Moldavia) break; case "sz": BroswerLanguage = "sz";// Sami (Lappish) break; case "sr": BroswerLanguage = "sr";// Serbian (Cyrillic) break; //case "sr": // BroswerLanguage = "sr";// Serbian (Latin) // break; case "sk": BroswerLanguage = "sk";// Slovak break; case "sl": BroswerLanguage = "sl";// Slovenian break; case "sb": BroswerLanguage = "sb";// Sorbian break; case "es": BroswerLanguage = "es";// Spanish (Spain, traditional) break; //case "es": // BroswerLanguage = "es";// Spanish (Spain, modern) // break; case "es-ar": BroswerLanguage = "es-ar";// Spanish (Argentina) break; case "es-gt": BroswerLanguage = "es-gt";// Spanish (Guatemala) break; case "es-cr": BroswerLanguage = "es-cr";//Spanish (Costa Rica) break; case "es-pa": BroswerLanguage = "es-pa";// Spanish (Panama) break; case "es-do": BroswerLanguage = "es-do";// Spanish (Dominican Republic) break; case "es-mx": BroswerLanguage = "es-mx";// Spanish (Mexico) break; case "es-ve": BroswerLanguage = "es-ve";//Spanish (Venezuela) break; case "es-co": BroswerLanguage = "es-co";// Spanish (Colombia) break; case "es-pe": BroswerLanguage = "es-pe";// Spanish (Peru) break; case "es-ec": BroswerLanguage = "es-ec";// Spanish (Ecuador) break; case "es-cl": BroswerLanguage = "es-cl";// Spanish (Chile) break; case "es-uy": BroswerLanguage = "es-uy";// Spanish (Uruguay) break; case "es-py": BroswerLanguage = "es-py";// Spanish (Paraguay) break; case "es-bo": BroswerLanguage = "es-bo";// Spanish (Bolivia) break; case "es-sv": BroswerLanguage = "es-sv";// Spanish (El Salvador) break; case "es-hn": BroswerLanguage = "es-hn";// Spanish (Honduras) break; case "es-ni": BroswerLanguage = "es-ni";// Spanish (Nicaragua) break; case "es-pr": BroswerLanguage = "es-pr";// Spanish (Puerto Rico) break; case "sx": BroswerLanguage = "sx";// Sutu break; case "sv": BroswerLanguage = "sv";// Swedish break; case "sv-fi": BroswerLanguage = "sv-fi";// Swedish (Finland) break; case "th": BroswerLanguage = "th";// Thai break; case "ts": BroswerLanguage = "";// Tsonga break; case "tn": BroswerLanguage = "tn";// Tswana break; case "tr": BroswerLanguage = "tr";// Turkish break; case "uk": BroswerLanguage = "uk";// Ukrainian break; case "ur": BroswerLanguage = "ur";// Urdu break; case "ve": BroswerLanguage = "ve";// Venda break; case "vi": BroswerLanguage = "vi";// Vietnamese break; case "xh": BroswerLanguage = "xh";// Xhosa break; case "ji": BroswerLanguage = "ji";// Yiddish break; case "zu": BroswerLanguage = "zu";//Zulu break; // case "": // BroswerLanguage = "";// // break; //case "": // BroswerLanguage = "";// // break; default: BroswerLanguage = "NoData"; break; } return BroswerLanguage; //if (strClicent.Contains("zh-cn") == true) //{ // return BroswerLanguage = "zh-cn"; //} //if (strClicent.Contains("zh-tw") == true) //{ // return BroswerLanguage = "zh-tw"; //} //if (strClicent.Contains("zh-hk") == true) //{ // return BroswerLanguage = "zh-hk"; //} //if (strClicent.Contains("zh-sg") == true) //{ // return BroswerLanguage = "zh-sg"; //} //else if (strClicent.Contains("en-us") == true) //{ // return BroswerLanguage = "en-us"; //} //else //{ // return BroswerLanguage = "NoData"; //} } }