C
C#2y ago
GIGA BRAIN

Getting a string to only accept 0's and 1's

I don't understand what is wrong with this line of code in particular: bool result = userInput.All(c=>Char.IsLetter(c) && c=='1' && c=='0');
10 Replies
Jester
Jester2y ago
it cant be '1' and '0' at the same time
GIGA BRAIN
GIGA BRAINOP2y ago
oh i see should i make two bool results then? or would that work
mtreit
mtreit2y ago
Use an or Not an and
Jester
Jester2y ago
char is letter and (1 or 0)
GIGA BRAIN
GIGA BRAINOP2y ago
oh i'll try that rq now that I think about it, does this strong not work in my case?
GIGA BRAIN
GIGA BRAINOP2y ago
GIGA BRAIN
GIGA BRAINOP2y ago
i originally had the if statement set to false, but even if I put in 0's and 1's it would still think that I put something else is there a way to modify the bool result to only have c=='1' or c=='0'? i think the char.isLetter is the problem
Jester
Jester2y ago
i think 1 and 0 arent letters you should remove the is lettee
GIGA BRAIN
GIGA BRAINOP2y ago
would I replace the IsLetter with IsDigit in that case? oh perfect that was it
Jester
Jester2y ago
just is 0 or 1 is enough
Want results from more Discord servers?
Add your server