0
Can someone tell me what my mistake is?
This is a college exercise https://code.sololearn.com/ccl1mlcC7pYP/?ref=app https://code.sololearn.com/ccl1mlcC7pYP/?ref=app
11 Antworten
+ 5
You can remove all unnecessary Console.ReadLine(); commands.
And in your foreach loop use sub instead of bits.
And write text inside the loop without the sub before the loop
And only the subs inside the loop.
😉
0
At the end: Text before and after @ symbol : { bits}") change bits to sub.
You make foreach call every sub in bits, but you say your computer to print bits.
also second if statement should be else if- why check @ presence if input is empty? the same way should be treaten rest of your code. I give invalid input, still get message "your letters before and after @"
0
is using a sub variable after var compulsion for string split function?
0
I tried using sub instead of bits but it didn't work.....
0
Can you edit my code and post it in the chat if you have picked my mistake, please?
0
namespace Sololearn
{
class Program
{
static void Main(string[] args)
{
string email;
string atsign = "@";
Console.WriteLine("Please enter an email:");
email = Console.ReadLine();
Console.WriteLine(email);
if(string.IsNullOrWhiteSpace(email))
{ Console.WriteLine("email cannot be empty");
Console.ReadLine(); }
else if (!email.Contains("@"))
{ Console.WriteLine(" Email must contain an @ symbol");
Console.ReadLine(); }
else{
string[] bits = email.Split('@');
Console.WriteLine(quot;Text before @: {bits[0]}\nText after @: {bits[1]}");
}
}
}
}
0
Its 5am here and my brain aint able to explain changes now, hope ill find time during day. Try not search for others code to learn but learn to read your own code, try what its doing with diferent inputs, find your own way to fix it ao it do what you want
0
Tbh..... I didn't get it
0
What and why did you do? I mean the bit thingy...
0
foreach ( var sub in bits)
{ Console.WriteLine(quot; Text before and after @ symbol : {bits}"); Console.ReadLine(); }
}
Your code says: foreach sub in bits array, write line with bits.
Thats wrong- you need your code to say: foreach sub in bits array, write line with sub
0
What i did, i removed the foreach loop, repaired the function to continue only if @ is included. If yes, split line in two string(one array of two strings) and output text before(bits[0]) and after(bits[1])