❔ Help with strings
I put it here because I think it is a quick and very basic question, I have a string with a specific series of letters and I want to check that another string that the user writes by console can ONLY have letters of that string. How can I do it? I mean this is what I have so far but it doesn't work. In the first case I want to be able to enter only those numbers and then I want to be able to enter only one of those letters but it is not well done.
11 Replies
Loops
Loop over one string
Inside loop over the other
Basically, compare each character of one string with each character of the other
If the first letter of the string you want to check isn't any of the characters you want to check for, return
false
from the method
If it is, check the second letter
If you can go over all the letters, return true
ok, thanks, I thought it would be easier without having to do that but i guess is not happenning I'll see if I can fix it and post it here in a little while, but thanks.
I mean, you can use LINQ
.All()
with .Contains()
should do the trickI cant
I have to do it in a "rudimentary" way, is the aim of the exercise.
Loops it is, then
Diddy#2634
REPL Result: Success
Console Output
Compile: 557.327ms | Execution: 73.035ms | React with ❌ to remove this embed.
not like that it doesn't
Windows10CE#8553
REPL Result: Success
Console Output
Compile: 602.280ms | Execution: 34.077ms | React with ❌ to remove this embed.
pretty sure you wanted the char[] version
Windows10CE#8553
REPL Result: Success
Console Output
Compile: 540.183ms | Execution: 73.077ms | React with ❌ to remove this embed.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.