当前位置: 代码迷 >> 综合 >> C#程序设计 A3.1 字符串处理(Console)
  详细解决方案

C#程序设计 A3.1 字符串处理(Console)

热度:77   发布时间:2023-10-20 15:35:40.0
public A31Page() {string str = "";while (true){Console.WriteLine("请输入一个长度大于3的字符串:");str = Console.ReadLine();if (str.Length <= 3){Console.WriteLine("字符串长度不符合要求,请重新输入!");continue;}Console.WriteLine();break;}//字符串的长度Console.WriteLine("(1)字符串的长度为:{0}",str.Length);//出现a的位置int i = str.IndexOf('a');if (i > -1){Console.WriteLine("(2)第一个出现a的位置是:{0}", i);}else {Console.WriteLine("(2)字符串中不包含字母a");}//插入helllostring str1 = str.Insert(3, "hello");Console.WriteLine("(3)插入hello后的结果:{0}",str1);//用me替换hellostring str2 = str1.Replace("hello", "me");Console.WriteLine("(4)将hello替换me后的结果为:{0}",str2);//以m为分割符string [] arr = str2.Split('m');Console.WriteLine($"(5)以m为分隔符分离后的字符串有{arr.Length}个:");for (int j = 0; j< arr.Length; j++) {Console.Write(arr[j]+" ");}Console.WriteLine();}

 

  相关解决方案