題目要求:
class Program { static void Main(string[] args) { Console.WriteLine("請輸入正確的郵箱地址,以 @sina.com 結尾"); string us =Convert.ToString(Console.ReadLine()); string str1 = us.Replace("@", ""); int count = us.Length - str1.Length; string str2 = us.Replace(".", ""); int count2 = us.Length - str2.Length; int count3 = us.Length - 1; int xl=us.IndexOf(".")-us.IndexOf("@"); bool mw = (us.IndexOf("@sina.com") == (us.Length-9)); while (count == 1 && count2 == 1 && us.IndexOf("@") > 0 && us.IndexOf(".") > us.IndexOf("@") && us.IndexOf(".")<count3) { if (xl != 1 && us.Contains("@sina.com") && mw) { Console.WriteLine("正確"); } else { Console.WriteLine("輸入的郵箱地址有誤"); } break; } Console.ReadLine(); } }
2016 - 07 - 20