There is no simple function that does that, you are going to have to check for them all separately:
string searchIn = "C# Java Delphi Linux PHP";
string searchFor = "C# PHP";
string[] findThese = searchFor.Split(' ');
bool hasAll = true;
foreach (string s in findThese)
{
if (!searchIn.Contains(s))
{
hasAll = false;
break;
}
}
if (hasAll)
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
"10ks, these really work out. can you please comment the code for me as i can't understand exactly what it does. - bmw318mt 41 mins ago"
You are kidding, right? :laugh:
You aren't kidding, are you? Oh, dear, it's going to be one of those days...
Firstly, don't use textspeak here: it annoys some people, and it confuses the non-native English speakers - they can't look it up in a dictionary, so they can't work out what you are saying. There are a lot of non-native English people here...
string searchIn = "C# Java Delphi Linux PHP";
Declares a string variable, called "searchIn" - you called this "temp" but it makes it a lot easier to work out what is happening if you always use description names (VS Intellisense auto completes so it is less effort as well).
It assigns a string to it which contains the text you want to search. Normally,I would expect this to be a parameter to a method.
string searchFor = "C# PHP";
Declares a second string variable, called "searchFor", and assigns it the terms you want to search for (hence the name...).
Again, normally a method parameter.
string[] findThese = searchFor.Split(' ');
Declares an array of string variables called "findThese".
The "searchFor" string is split into separate strings, each delimited by a space. So, with the "searchFor" string being "C# PHP", the Split would create two new strings, "C#" and "PHP". These are collected together into an array of strings, and assigned to the "findThese" variable.
bool hasAll = true;
Declares a variable called "hasAll" which can have one of two values only: "true" and "false". Defaults it to being "true".
foreach (string s in findThese)
Sets up a loop, extracting each string from the string array "findThese" and assigning it in turn to the string variable "s".
In the example above, the code in the body of the loop will be executed twice, the first time with "s" equal to "C#" and the second with "s" equal to "PHP"
{
Indicates the start of the loop body
if (!searchIn.Contains(s))
Searches the string "searchIn" to see if the current value of "s" is within it. If it is not (as indicated by the '!' character) then execute the code block below it.
If the string is in there, do not execute the code below
{
Indicates the start of code to be executed if the string is not found.
hasAll = false;
Because at least one of the serached for strings is not in the input, we need to mark that the input does not
contain all the strings we want. Changes the value of "hasAll" to "false" = the opposite of what it started off with
break;
Because we know the input string does not contain all the strings we are looking for, we don't need to look any more - exit from the loop immediately.
}
Indicates the end of the conditionally executed code.
}
Indicates the end of the loop.
if (hasAll)
If we found all strings that were wanted were in the input string, execute the code below.
{
Indicates the start of code to be executed if the searched for strings were all there.
Console.WriteLine("Yes");
Writes the message "Yes" to the console.
}
Indicates the end of code to be conditionally executed
else
If we executed the code above, don't execute the code below.
If we didn't execute the code above, then execute the code below.
{
Indicates the start of code to be executed if the searched for strings were not all there.
Console.WriteLine("No");
Writes the message "No" to the console.
}
Indicates the end of code to be conditionally executed
Do not expect anyone to do that for you again!
It took about ten times longer to write the explanation than it did to write the code...