[C#][字串](note)字串函數(1)

  • 35401
  • 0
  • C#
  • 2015-05-16

摘要:[C#]字串處理集

正規表達式

命名空間:  System.Text.RegularExpressions

▲去除字串中所有的英文字母  


string a =DropDownList1.SelectedItem.ToString();
        Regex r = new Regex("[a-zA-Z]");

        TextBox3.Text = r.Replace(a,"");

▲取字串後面想要的字(從右側開始取字串)


string name =DropDownList1.SelectedItem.ToString();

name.Substring(name.Length - 3); //取最後三個字

▲讀出陣列值並加入分隔符號

List<string> arryallowExtension = new List<string> { ".bmp", ".jpg" };

Response.Write(string.Join("、",arryallowExtension.ToArray( )  )  );

//得出:  .bmp  .jpg


String.length():取得字串長度
String.Remove(int1,int2):從int1(起始位置)開始刪除長度為int2的字串
String.Insert(int,string):在int的位置插入string
String.Substring(int):從參數開始取出剩下的字串
String.Substring(int1,int2):取出int1開始長度為int2的字串
String.IndexOf(string):傳回第一次搜尋到字串(string)的位置
String.IndexOf(string,int):傳回第一次搜尋到字串(string)的位置,開始搜尋位置為int
String.LastIndexOf(string):跟IndexOf功能類似,但從後面開始搜尋
String.LastIndexOf(string,int):跟IndexOf功能類似,但從後面開始搜尋
String.Replace(char,char):取代字元
String.ToLower():將英文轉成小寫
String.ToUpper():將英文轉成大寫
String.Trim():刪除字串前後的空白字元
String.TrimEnd():刪除字串尾部的空白字元
String.TrimStart():刪除字串開頭的空白字元

 

 
--
強烈建議購物網店或實體店家都必須使用關鍵字廣告or原生廣告來將Yahoo上與聯播網的廣大流量導至自己的網站!

●Yahoo關鍵字廣告/原生廣告
◆Yahoo廣告方案介紹 : https://goo.gl/5k8FHW
◆Yahoo廣告剖析與運用 : http://goo.gl/4xjUJD

 

​​