字符竄函數

字符串函數,其中包括。(1)字符串的大小寫轉換。(2)字符串去收尾空格。(3)字符串分隔符表示

Code:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.   
  6. namespace String1  
  7. {  
  8.     class Program  
  9.     {  
  10.         static void Main(string[] args)  
  11.         {  
  12.             /* 
  13.              * 字符串的大小寫改變 
  14.             string s = "Hello"; 
  15.             string s1 = s.ToLower(); 
  16.             string s2 = s1.ToUpper(); 
  17.             Console.WriteLine("輸出字符串 s :{0}",s); 
  18.             Console.WriteLine("將字符串s中的大寫變小寫s1 :{0}",s1); 
  19.             Console.WriteLine("將字符串s1中的小寫變大寫s2 : {0}", s2); 
  20.             Console.WriteLine("重新查看s 字符串內容是否改變 :{0}", s); 
  21.             
  22.              */  
  23.   
  24.             /* 
  25.              *  
  26.              * Trim() 函數能夠去掉字符串首位的空格,但是不能去掉中間的空格 
  27.              *  
  28.              * string s = "    faf    "; 
  29.             string s1 = s.Trim(); 
  30.             Console.WriteLine("原字符串 s :{0}", s); 
  31.             Console.WriteLine("調用Trim()去掉兩邊空白後的字符串 :{0}", s1); 
  32.             */  
  33.   
  34.             /* 
  35.              * 字符串的比較 
  36.              *  
  37.             string s = "abc"; 
  38.             //bool b = "abc".Equals(s); 
  39.             bool b = "abc".Equals("ABC", StringComparison.OrdinalIgnoreCase); 
  40.             //StringComparison.OrdinalIgnoreCase   忽略大小寫格式 
  41.              
  42.             Console.WriteLine("bool 使用的返回結果 :{0}", b); 
  43.              
  44.             int i = "abc".CompareTo(s); 
  45.             int j = "abc".CompareTo("123"); 
  46.             Console.WriteLine("比較結果i = {0},j = {1}",i,j); 
  47.             */  
  48.   
  49.             //string[] Split(param separater)  
  50.             //Split 將字符串按照指定的分隔符分隔成字符串數組;  
  51.             /* 
  52.             string s = "aaa,bb,ccc|dddd,eeee"; 
  53.             string[] s1 = s.Split(',','|'); //因爲是param 格式,所以可以是多個不同的參數 
  54.             foreach (string item in s1) 
  55.                 Console.WriteLine(item); 
  56.             */  
  57.             /* 
  58.             //處理字符串中的空字符串 
  59.             string s2 = "aaa,dd,,dfaf,ddd"; 
  60.             string[] s3 = s2.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries); 
  61.             foreach (string item in s3) 
  62.                 Console.WriteLine(item); 
  63.             */  
  64.   
  65.             string s1 = "我是傑克遜我是麥克斯我是韓庚";  
  66.             string[] str = s1.Split(new string[] { "我是" }, StringSplitOptions.RemoveEmptyEntries);  
  67.             foreach (string item in str)  
  68.                 Console.WriteLine(item);  
  69.   
  70.             string s = "2010-10-23";  
  71.             string[] s1 = s.Split('-');  
  72.             Console.WriteLine("{0}年{1}月{2}日",s1[0],s1[1],s1[2]);  
  73.   
  74.             Console.ReadKey();  
  75.         }  
  76.     }  
  77. }  
  78.    

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章