程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> String Control,stringcontrol

String Control,stringcontrol

編輯:C#入門知識

String Control,stringcontrol


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 是可數還是不可數

1.線;細繩;帶子[U][C]
I need a piece of string to tie this parcel up.
我需要一根細繩把這包裹扎起來。
2.(附在衣服等上的)帶子,絲帶[C]
3.(穿珠,錢等的)串線,串繩[C]
4.一串,一行,一列[C][(+of)]
A string of accidents happened at that corner.
在那個轉角發生了一連串的事故。
The monk wears a string of beads.
和尚戴著一串念珠。
5.(植物的)纖維,筋[C]
6.(樂器等的)弦[C]
There are four strings on a violin.
小提琴有四根弦。

由此可見第一個意思“線;細繩;帶子[U][C]”
既可數 又有時不可數以外
其余的意思的 都可數
 

aspnet怎把string類型轉換為控件類型

Button btn=this.Page.FindControl("Button的ID") as Button;
if(btn!=null)
{
...
}
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved