标签:
static void Main(string[] args) { string str = "Now is time and"; string word; ArrayList words = new ArrayList(); int pos = str.IndexOf(" "); while (pos>0) { word = str.Substring(0,pos); words.Add(word); str = str.Substring(pos+1,str.Length-(pos+1)); pos = str.IndexOf(" "); if (pos==-1) { word = str.Substring(0,str.Length); words.Add(word); } } foreach (var item in words) { Console.Write(" "+item); } Console.ReadKey(); }
data="mike,stove";
sdata=data.Split(new char[]{‘,‘},data.length);
String.Join(",",sdata);
static void Main(string[] args) { string s1 = "footbar"; string s2 = "footbar"; if (s1.Equals(s2)) { Console.WriteLine("good"); } else { Console.WriteLine("bad"); } string s3 = "footbaa"; string s4 = "footbas"; Console.WriteLine(s1.CompareTo(s2)); Console.WriteLine(s1.CompareTo(s3)); Console.WriteLine(s1.CompareTo(s4)); Console.WriteLine(string.Compare(s1,s2)); Console.WriteLine(string.Compare(s1,s3)); Console.WriteLine(string.Compare(s1,s4)); string se = "goodmorning"; Console.WriteLine(se.EndsWith("ing")); Console.WriteLine(se.StartsWith("good")); string a1 = "hello, .welcome to my class"; string a2 = "mike"; int pos = a1.IndexOf(","); a1= a1.Insert(pos+2,a2); Console.WriteLine(a1); a1 = a1.Remove(pos+2,a2.Length); Console.WriteLine(a1); Console.WriteLine("goodsssgoodsssgood".Replace("goo","a")); Console.WriteLine("hello".PadLeft(10)); Console.WriteLine("hello".PadRight(10)); Console.WriteLine(string.Concat("hello"," , ","world")); Console.WriteLine("hellO".ToUpper()); Console.WriteLine("HELLO".ToLower()); string[] names = new string[] {" mi ke "," dav id "," r a y "}; char[] chararray = new char[] { ‘ ‘}; for (int i = 0; i <=names.GetUpperBound(0); i++) { names[i] = names[i].Trim(chararray[0]); //names[i] = names[i].TrimEnd(chararray[0]); } for (int i = 0; i <names.Length; i++) { Console.Write(names[i]); } string[] htmlComments = new string[] { "<!--startpage -->", "<!--startpage -->", "<!--startpage -->", "<!--startpage -->" }; char[] commentChars = new char[] {‘<‘,‘!‘,‘-‘,‘>‘}; for (int i = 0; i < htmlComments.Length; i++) { htmlComments[i] = htmlComments[i].Trim(commentChars); // htmlComments[i] = htmlComments[i].TrimEnd(commentChars); } for (int i = 0; i < htmlComments.GetUpperBound(0); i++) { Console.WriteLine(" "+htmlComments[i]); } Console.ReadLine(); }
StringBuilder stBuff = new StringBuilder(); stBuff.Insert(0,"hello",3); stBuff.Append("world"); stBuff.Insert(5,","); char[] chars = new char[] {‘t‘,‘h‘,‘e‘,‘r‘,‘e‘ }; stBuff.Insert(5,""+new string(chars)); Console.WriteLine(stBuff); Console.WriteLine(stBuff.Remove(9,5)); Console.ReadLine();
标签:
原文地址:http://www.cnblogs.com/futengsheng/p/5648751.html