C# String

來源:互聯網
上載者:User

標籤:

string 類表示一個字元序列(零個或更多 Unicode 字元), string 是 .NET Framework 中 String 的別名            string str;// 聲明字串
           

 1             string str;// 聲明字串 2             str = "Hello World!"; //為字串賦值 3             string str = "";//Null 字元串 4             string str=String.Empty;// Null 字元串,唯讀; 5             char ch=str.Chars[0];//擷取字串str的第1個字元; 6             int i=str.Length; //擷取字串長度 7             String.Contact("A","B");// 連接字串 8             str.Contains("ABC");// 返回字元中是否包含字串ABC 9             str.EndsWith("ABC");//返回字元中是否以字串ABC結尾10             String.Format("This is a {0} statement;", str); //格式化字串11             str.IndexOf(‘A‘);//  返回字串str中字元A的第一個索引12             str.LastIndexOf(‘A‘);//返回字串str中字元A最後一個索引13             str.Insert(0, "ABC");//在字串str的位置0處插入ABC14             str.PadLeft(10,‘A‘);// 在字串str左側補充字元A,使其總長度達到1015             str.PadRight(10, ‘A‘);//在字串str右側補充字元A,使其總長度達到1016             str.Remove(2);//在字串str中刪除2個字元;17             str.Replace(‘A‘, ‘B‘);// 在字串中使用B替代A18             char[] ch = str.ToCharArray();//將字串str轉化成字元數組19             str.ToLower();//將str轉化成小寫字母20             str.ToUpper();//將str轉化成大寫字母21             str.Trim();//去除str的空格22             str.TrimStart();//去除str的起始空白字元23             str.TrimEnd();//去除str的末尾空白字元

 

C# String

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.