首页 > 代码库 > String Control

String Control

using System;using System.Collections.Generic;using System.Text;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;//using Microsoft.TeamFoundation.WorkItemTracking.Controls;namespace COMP{    /// <summary>    /// 字符串操作    /// </summary>    public class StringControl    {                /// <summary>        /// 客户端浏览器        ///涂聚文        ///2009-08-08        /// </summary>        /// <param name="strClient">客户端环境</param>        /// <param name="ver">浏览器版</param>        /// <returns>返回浏览器名称</returns>        public string getBrowser(string strClient, out string ver)        {            //Camino            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("Camino") == true)//有待验证            {                strBrowser = "Camino";                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>        /// 客户端操作系统        /// </summary>        /// <param name="strClient">客户端环境</param>        /// <returns>返回操作系统名称</returns>        public string getPlatform(string strClient)        {            string OpertorSystem =String.Empty;            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("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            {                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 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>        /// 浏览器语言        /// </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();            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";            }                     }    }}

 

String Control