C
C#7mo ago
Kirieshka

Please, help me with program logic

Hi, I don't care. I'm fighting over this for the second day. Such a task: I have an integer list with some values, such as 65 and 87. And there is a string in which can be written at all anything, numbers, symbols, characters, letters, and so on, you need to check if this string contains the value from this list. I have no idea how to decide. Please help me
17 Replies
Angius
Angius7mo ago
string.Contains() In a loop
Pobiega
Pobiega7mo ago
a list can contain multiple values thou, so what exactly do you mean by "check if this string contains the value from this list"?
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Kirieshka
KirieshkaOP7mo ago
Sorry for my bad English. I mean check whether the string contains only values from list Integer values*
Pobiega
Pobiega7mo ago
uh so if your list is [65,67] and your string is 65x67 that would fail, because x was in there?
Kirieshka
KirieshkaOP7mo ago
I can give a more clear example if you don't understand me.
Pobiega
Pobiega7mo ago
please do
Kirieshka
KirieshkaOP7mo ago
Look, I have an integer list. For example, it contains 65, 57, 85. And there is a string: "hei+6528/&9294-65=87%57z" need this string to be checked for whether it contains only numbers from list. Toot if there is something other than 65, 57, 85, in our case it is 6528, 9294 and 87, then returns false. Otherwise, if our line is approximately: "hei+*/&65=%57z", true Now more clear?
Pobiega
Pobiega7mo ago
ah okay so you want to essentially extract all delimited integers from the string, and make sure all those exist in your list of integers
Kirieshka
KirieshkaOP7mo ago
Yes
Pobiega
Pobiega7mo ago
An excellent usecase for a parser
Kirieshka
KirieshkaOP7mo ago
Can I just a little more? I don't understand what we're talking about.
Pobiega
Pobiega7mo ago
well, essentially you want to loop over the string, char by char if its a number, add it to a buffer. if its not, yield the content of the buffer as an int, then clear the buffer
Kirieshka
KirieshkaOP7mo ago
I think I'm starting to understand, a second, I need to check something
Pobiega
Pobiega7mo ago
var input = "ei+6528/&9294-65=87%57z";
var numbersFound = FindNumbers(input).ToList();
Console.WriteLine($"Found {numbersFound.Count} numbers: {string.Join(", ", numbersFound)}");
var input = "ei+6528/&9294-65=87%57z";
var numbersFound = FindNumbers(input).ToList();
Console.WriteLine($"Found {numbersFound.Count} numbers: {string.Join(", ", numbersFound)}");
should printFound 5 numbers: 6528, 9294, 65, 87, 57 if I understood you correct then, instead of printing, we would just check if all the numbers exist in your list of integers
Kirieshka
KirieshkaOP7mo ago
Finally. Thank you very much for your time. You put me on the right thoughts I could find a solution myself. Thanks for working with me. Thank you very much
Pobiega
Pobiega7mo ago
no problems
Want results from more Discord servers?
Add your server