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");
}
//插入helllo
string str1 = str.Insert(3, "hello");
Console.WriteLine("(3)插入hello后的结果:{0}",str1);
//用me替换hello
string 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();
}