字符串函数,其中包括。(1)字符串的大小写转换。(2)字符串去收尾空格。(3)字符串分隔符表示
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace String1
- {
- class Program
- {
- static void Main(string[] args)
- {
- /*
- * 字符串的大小写改变
- string s = "Hello";
- string s1 = s.ToLower();
- string s2 = s1.ToUpper();
- Console.WriteLine("输出字符串 s :{0}",s);
- Console.WriteLine("将字符串s中的大写变小写s1 :{0}",s1);
- Console.WriteLine("将字符串s1中的小写变大写s2 : {0}", s2);
- Console.WriteLine("重新查看s 字符串内容是否改变 :{0}", s);
- */
- /*
- *
- * Trim() 函数能够去掉字符串首位的空格,但是不能去掉中间的空格
- *
- * string s = " faf ";
- string s1 = s.Trim();
- Console.WriteLine("原字符串 s :{0}", s);
- Console.WriteLine("调用Trim()去掉两边空白后的字符串 :{0}", s1);
- */
- /*
- * 字符串的比较
- *
- string s = "abc";
- //bool b = "abc".Equals(s);
- bool b = "abc".Equals("ABC", StringComparison.OrdinalIgnoreCase);
- //StringComparison.OrdinalIgnoreCase 忽略大小写格式
- Console.WriteLine("bool 使用的返回结果 :{0}", b);
- int i = "abc".CompareTo(s);
- int j = "abc".CompareTo("123");
- Console.WriteLine("比较结果i = {0},j = {1}",i,j);
- */
- //string[] Split(param separater)
- //Split 将字符串按照指定的分隔符分隔成字符串数组;
- /*
- string s = "aaa,bb,ccc|dddd,eeee";
- string[] s1 = s.Split(',','|'); //因为是param 格式,所以可以是多个不同的参数
- foreach (string item in s1)
- Console.WriteLine(item);
- */
- /*
- //处理字符串中的空字符串
- string s2 = "aaa,dd,,dfaf,ddd";
- string[] s3 = s2.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries);
- foreach (string item in s3)
- Console.WriteLine(item);
- */
- string s1 = "我是杰克逊我是麦克斯我是韩庚";
- string[] str = s1.Split(new string[] { "我是" }, StringSplitOptions.RemoveEmptyEntries);
- foreach (string item in str)
- Console.WriteLine(item);
- string s = "2010-10-23";
- string[] s1 = s.Split('-');
- Console.WriteLine("{0}年{1}月{2}日",s1[0],s1[1],s1[2]);
- Console.ReadKey();
- }
- }
- }