0
Is it possible to check if a string contains an item from an array?
Essentially I have a program that takes user input and splits the words up and stores them individually in an array. I have another array that contains numbers and symbols. I need to search the first array for strings containing those numbers and symbols. I need to do this at least twice within the program (hence using an array for the numbers and symbols to save code). I essentially want to do this: if (s.Contains (numberSymbols[ ])){} which doesn't work. How should I do this?
2 Respuestas
0
You should call a method of array.
if (numberSymbols.Contains (yourstring)).
It should be works, if "yourstring" is alone string variable, But by your description, I am affraid, you want to ask "if this array contains whichever string item from another array. And this is difficulty in one method. Maybe a solution should be a complex query in Linq, But the simplest way is use a loop
foreach (string sItem in sArray)
{if (numberSymbols.Contains (sItem)) ....}
0
It sounds to me that each array depends on the other. If thats the case you should think of using a dictionary where you have a key, value pair. Easier to find a certain value with a given key. Correct me if i am wrong about the array dependencies.