using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { string str = "中国"; int Len = str.Length; Console.WriteLine(Len); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("中华"); sb.Append("人民"); sb.Append("共和国"); Console.WriteLine(sb); string sl = sb.ToString().Substring(1, 1); Console.WriteLine(sl); str = "中国 人民"; Console.WriteLine(char.IsWhiteSpace(str, 2)); Console.WriteLine(char.IsPunctuation('A')); Console.WriteLine((int)'中'); Console.WriteLine((char)22269); str = " 中国 "; Console.WriteLine(str); Console.WriteLine(str.Trim()); str = str.Replace("国", "央"); Console.WriteLine(str); string s = "1,2,3,4,5,"; s = s.Substring(0, s.Length - 2); Console.WriteLine(s); str = "aaajsbbbjSccc"; string[] sArray = Regex.Split(str, "js", RegexOptions.IgnoreCase); foreach (string i in sArray) { Console.WriteLine(i.ToString() + "/n"); } str = "aaa,bbb,ccc"; sArray = str.Split(','); foreach (string i in sArray) { Console.WriteLine(i.ToString()); } str = "aaajsbbbjsccc"; sArray = str.Split(new char[2] {'j', 's'}); foreach(string i in sArray) { Console.WriteLine(i.ToString()); } Console.WriteLine(12345.ToString("n")); Console.WriteLine(12345.ToString("c")); Console.WriteLine(12345.ToString("e")); Console.WriteLine(12345.ToString("f4")); Console.WriteLine(12345.ToString("x")); Console.WriteLine(12345.ToString("p")); string a = "123456789"; a = int.Parse(a).ToString("##-###-####"); Console.WriteLine(a); a = "123456789"; a = a.Insert(5, "-").Insert(2, "-"); Console.WriteLine(a); a = "123456789"; Regex reg = new Regex(@"^(/d{2})(/d{3})(/d{4})$"); a = reg.Replace(a, "$1-$2-$3"); Console.WriteLine(a); string str1 = ""; for (int n = 0; n < 21; n++) { str1 += "A"; } Console.WriteLine(str1); string str2 = new string('A', 21); Console.WriteLine(str2); Random r = new Random(); int n1 = r.Next(); Console.WriteLine(n1); int n2 = r.Next(10); Console.WriteLine(n2); int n3 = r.Next() % 10; Console.WriteLine(n3); int n4 = r.Next(1,20); Console.WriteLine(n4); double d5 = r.NextDouble(); Console.WriteLine(d5); string myString = "1234"; int myint = 0; //方法1 myint = Convert.ToInt32(myString); Console.WriteLine(myint); //方法2 myint = Int32.Parse(myString); Console.WriteLine(myint); //方法3 Int32.TryParse(myString, out myint); Console.WriteLine(myint); double y = Math.IEEERemainder(5.0, 3.0); Console.WriteLine(y); int ys; double d = Math.DivRem(5, 3, out ys); Console.WriteLine(d.ToString() + "/n" + ys.ToString()); Console.ReadKey(); } }