/Practice: Determine if the mailbox format is correct
1. There is only one @ contains @ indexof @=lastindexof
2. Cannot start with @ indexof! = 0
There is at least one after [email protected].
[email protected] and. Can't stay together.
5. Cannot end with.
Console.Write ("Please enter your e-mail address:"); strings =Console.ReadLine (); if(S.contains ("@")==true)//does it contain @ { if(S.indexof ("@") !=0&&s.indexof ("@") ==s.lastindexof ("@") )//@ is not the beginning, only one @ { stringSS = S.substring (S.indexof ("@"));//intercept the string at the beginning of @ if(SS. Contains (".")==true)//characters that contain. { if(SS. IndexOf (".")! =1&&ss. EndsWith (".")==false)//@ Heel. Do not stay together, and do not end with.{Console.WriteLine ("the mailbox you entered is in the correct format! "); } Else{Console.WriteLine ("the mailbox you entered is not formatted correctly"); } } Else{Console.WriteLine ("the mailbox you entered is not in the correct format! "); } } Else{Console.WriteLine ("the mailbox you entered is not formatted correctly"); } } Else{Console.WriteLine ("the mailbox you entered is not formatted correctly"); }
The second Kind
Console.Write ("Please enter your e-mail address:"); strings =Console.ReadLine (); BOOLx = S.contains ("@");//determine if there is a @ in the input character intA = S.indexof ("@");//define first occurrence @ index number a intb = S.lastindexof ("@");//define last occurrence @ index number B stringSS = S.substring (a);//intercept the string at the beginning of @ BOOLy = ss. Contains (".");//determine if the SS contains. intc = ss. IndexOf (".");//appears. Index number of the first time BOOLz = ss. EndsWith (".");//Judging the end is not. if(x = =true&& A = = b && y = =true&& C >1&& Z = =false) {Console.WriteLine ("the mailbox you entered is in the correct format! "); } Else{Console.WriteLine ("The format of the mailbox you entered is incorrect! "); }
Determine if the mailbox format is correct