1 using System; 2 3 namespace _01_Console01 4 { 5 class Program 6 { 7 public static void Main(string[] args) 8 { 9 // 获取字符在字符串的位置 10 string email = "zhangsan@qq.com"; 11 int position = email.IndexOf("@"); 12 13 // 获取字符串的长度 14 string pwd = "1234567890"; 15 int pwdLength = pwd.Length; 16 17 // 两个字符串是否相等 18 string num1 = "zhangsan"; 19 string num2 = "zhangsan"; 20 // == 和 Equals 都可以 21 bool b = num1.Equals(num2); 22 23 // 字符串截取。从第一个字符开始,到'@'结束(不包括) 24 string userName = email.Substring(0, email.IndexOf("@")); 25 26 // 字符串占位 27 string info = "用户名:{0},邮箱名:{1}"; 28 info = string.Format(info, userName, email); 29 30 // 去除前后多余空格 31 string num3 = " lisi "; 32 num3 = num3.Trim(); 33 34 // 输出 35 Console.WriteLine("@在第{0}位",position); 36 Console.WriteLine("pwd长度为{0}",pwdLength); 37 Console.WriteLine("两个字符串相等:{0}",b); 38 Console.WriteLine("userName为:{0}",userName); 39 Console.WriteLine(info); 40 Console.WriteLine(num3); 41 Console.ReadKey(); 42 } 43 } 44 }