字符窜函数

字符串函数,其中包括。(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.    

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值