C#从控制台输入邮箱,要求邮箱中仅含有一个 @,然后截取邮箱中的用户名输出
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
int firstIndex = str.IndexOf("@");
int lastIndex = str.LastIndexOf("@");
if(firstIndex != -1 && firstIndex == lastIndex)
{
str = str.Substring(0, firstIndex);
}
Console.WriteLine("邮箱中的用户名是:" + str);
}
}

浙公网安备 33010602011771号