标签:
string s = "shdfidSHIdfid "; int changdu = s.Length;//返回字符串的长度,属性(有小扳手的) string a = s.Trim();//去除前后空格 string b = s.TrimEnd();//去除前空格 string c = s.TrimStart();// 去除后空格 string d = s.ToUpper();//转化为大写 string e = s.ToLower();//转化为小写 Console.WriteLine("长度:" + changdu); Console.WriteLine("原字符串:" + s); Console.WriteLine("去空格:" + a); Console.WriteLine("大写:" + d); Console.WriteLine("小写:" + e); //截取字符串,比较重要;字符串是有索引的,索引从0开始 string g=s.Substring (3,3); string h = s.Substring(3); Console.WriteLine("截取后"+ g); Console.WriteLine("截取"+h ); //查找索引, int i= s.IndexOf("fi");//查找某字符段在字符串中的索引,从0开始往后 int ii= s.IndexOf("fi",4); int j= s.LastIndexOf("fi");//查从后往前查 //替换 replace string k= s .Replace ("fi","123"); Console .WriteLine("新字符串"+ k); //分割需要用字符串 string ss = "a,s,d,fdf,gg,jj,ku"; string[] str = ss.Split(‘,‘); foreach (string l in str) { Console.WriteLine(l); }
标签:
原文地址:http://www.cnblogs.com/cf924823/p/4823563.html