C# String

來源:互聯網
上載者:User

標籤:

參考型別  string 常用的

1.判斷是否包含字串

string a="我ABCDEFG愛你";

Contains("字串");

bool  result=a.Contais("ABCDEFG")

返回:true;

2.分割符Split截取欄位

string  b="abcdef&fghij&klmn";

string [] c=b.split("&");

c[0]="abcdef";

c[1]="fghij";

c[2]="klmn";

3.連接字串的方法。

  3.1 Concat

    string stra="Hello";

    string strb="World!";

    string  newstr="";這裡順便提醒下自己string  str=null;string str="";的區別。一句話,前者未分配記憶體,後者為str 開闢了一個""的記憶體空間。

    newstr=Concat(stra,"",strb);

    輸出值:Hello World!

  3.2Join

    string stra="Hello";

    string strb="World!";

    string newstr="";

    string[] a={stra,strb};

    newstr=string.join("",a);

    輸出值:Hello word!

  3.3 "+" 這個 不說了吧,因為想起來了  加上這個

4.有分割  有串連  坑定也插入  Insert(int InsertIndex,string value) ,索引是從0開始的

  4.1  string stra="Hello";

    string strb="World!";

    string newstr="";

      newstr=stra.Insert(1,strb);

    輸出值:HWorld!ell

5.刪除  Remove() 從一個字串的制定位置開始,刪除指定數量的字元。

     Remove(int stratIndex,int count )

    string stra="Hello";

    string newStr="";

    newStr=stra.Remove(1,3);

    輸出值:Ho

    還想起一個,Trim();TrimStart();TrimEnd();去除Null 字元串的。

6.替換 Replace();

    Replace(char oldchar,char newchar);

    string stra="Hello";

    string newstr="";

    newstr=stra.Replace("ll","r");

    輸出:Hero

7.跟換大小寫

    ToUpper();

    ToLower();

    

       

    

 

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.