C
Join ServerC#
help
Getting a string to only accept 0's and 1's
GG3guap getter 30001/4/2023
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');

JJester1/4/2023
it cant be '1' and '0' at the same time
GG3guap getter 30001/4/2023
oh i see
GG3guap getter 30001/4/2023
should i make two bool results then?
GG3guap getter 30001/4/2023
or would that work
Mmtreit1/4/2023
Use an or
Mmtreit1/4/2023
Not an and
JJester1/4/2023
char is letter and (1 or 0)
GG3guap getter 30001/4/2023
oh
GG3guap getter 30001/4/2023
i'll try that rq
GG3guap getter 30001/5/2023
now that I think about it, does this strong not work in my case?
GG3guap getter 30001/5/2023

GG3guap getter 30001/5/2023
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
GG3guap getter 30001/5/2023
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
JJester1/5/2023
i think 1 and 0 arent letters
JJester1/5/2023
you should remove the is lettee
GG3guap getter 30001/5/2023
would I replace the IsLetter with IsDigit in that case?
GG3guap getter 30001/5/2023
oh perfect
GG3guap getter 30001/5/2023
that was it
JJester1/5/2023
just is 0 or 1 is enough
GG3guap getter 30001/5/2023
lemme try that
GG3guap getter 30001/5/2023

GG3guap getter 30001/5/2023
what do you mean by this?
GG3guap getter 30001/5/2023
something is definitely going over my head
JJester1/5/2023
c =>
JJester1/5/2023
nothin
GG3guap getter 30001/5/2023
oooooh
GG3guap getter 30001/5/2023
is that a pointer?
JJester1/5/2023
no you arent using pointers
GG3guap getter 30001/5/2023
wait no
GG3guap getter 30001/5/2023
so what does c => mean?
GG3guap getter 30001/5/2023
im guessing is character c 1 or 0?
Mmtreit1/5/2023
All
takes a function as input. You need to give it a function. =>
is a way to define a function (called a lambda) inline...JJester1/5/2023
like
Func<int, bool> isChar0or1 = c => c is '0' or '1';
Mmtreit1/5/2023
Func<char, bool>
Mmtreit1/5/2023
🙂
JJester1/5/2023
ok thats too complex
GG3guap getter 30001/5/2023
and just real quick, a function is also a method right
JJester1/5/2023
yeah i realised
JJester1/5/2023
sorry
JJester1/5/2023
its 1 am
JJester1/5/2023
i cant sleep
JJester1/5/2023
void Foo() { ... } or Action foo = () => { ... }
ate nearly the same thing but the last one is a delegate refering to a lambda instead of an ordenary method
ate nearly the same thing but the last one is a delegate refering to a lambda instead of an ordenary method
GG3guap getter 30001/5/2023
oh so its a difference regarding format?
JJester1/5/2023
ill try go sleep
GG3guap getter 30001/5/2023
for sure
GG3guap getter 30001/5/2023
thanks for the help!
JJester1/5/2023
it has some other differences
GG3guap getter 30001/5/2023
gotcha, def got a lot to learn
GG3guap getter 30001/5/2023
sleep well 🙂
JJester1/5/2023
lambdas are useful but can be tricky
JJester1/5/2023
thanks