Can someone tell me what my mistake is? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
22nd Sep 2023, 12:51 PM
Uzma Patel
Uzma Patel - avatar
11 Answers
+ 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. 😉
22nd Sep 2023, 1:41 PM
Stefanoo
Stefanoo - avatar
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 @"
25th Sep 2023, 4:16 AM
Drelda
Drelda - avatar
0
is using a sub variable after var compulsion for string split function?
25th Sep 2023, 10:18 PM
Uzma Patel
Uzma Patel - avatar
0
I tried using sub instead of bits but it didn't work.....
25th Sep 2023, 10:20 PM
Uzma Patel
Uzma Patel - avatar
0
Can you edit my code and post it in the chat if you have picked my mistake, please?
25th Sep 2023, 10:23 PM
Uzma Patel
Uzma Patel - avatar
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]}"); } } } }
26th Sep 2023, 4:19 AM
Drelda
Drelda - avatar
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
26th Sep 2023, 4:29 AM
Drelda
Drelda - avatar
0
Tbh..... I didn't get it
3rd Oct 2023, 10:18 AM
Uzma Patel
Uzma Patel - avatar
0
What and why did you do? I mean the bit thingy...
3rd Oct 2023, 10:18 AM
Uzma Patel
Uzma Patel - avatar
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
4th Oct 2023, 7:50 PM
Drelda
Drelda - avatar
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])
4th Oct 2023, 7:53 PM
Drelda
Drelda - avatar