static void test5() { string email = "老二好了像又怀了了孕了了!"; int result = email.IndexOf("孕了"); int result2 = email.IndexOf("了了!");//查询最后一个了了 string result3 = email.Substring(0, email.IndexOf("又"));//提取又前面的字符串内容 string result4 = email.Substring(5);//提取又后面的字符串内容,不指定起始位置直接给定长度; string name = "老二"; int old = 3; string string2 = string.Format("他的名字叫{0} 年龄{1}",name,old); //format 方法用于字符串拼接 string string3 = string.Format($"他的名字叫{name} 年龄{old}"); //等同上面语句,用$更直观 StringBuilder apen = new StringBuilder("3123");//创建一个stringbuiderl类的 apen 对象 apen.Append ("123");//字符串拼接在原来字符串上拼接 string apenstring = apen.ToString(); Console.WriteLine($"{result}"); Console.WriteLine($"{result2}"); Console.WriteLine($"{result3}"); Console.WriteLine($"{result4}"); Console.WriteLine(string2); Console.WriteLine(string3); Console.WriteLine(apenstring); } }
浙公网安备 33010602011771号