Is it possible to have the contain function find if the string contains 2 words or more? This is what I\'m trying to do:
string d = \"You hit someone for 50
string d = "You hit someone for 50 damage";
string a = "damage";
string b = "someone";
string c = "you";
if(d.Contains(a) && d.Contains(b))
{
Console.WriteLine(" " + d);
}
Console.ReadLine();
That is because the if statements returns false since d doesn't contain b + a i.e "someonedamage"
This is because d
does not contain b + a
(i.e. "someonedamage"
), and therefore the application just terminates (since your Console.ReadLine();
is within the if
block).
I just checked for a space in contains to check if the string has 2 or more words.
string d = "You hit someone for 50 damage";
string a = "damage";
string b = "someone";
string c = "you";
bool a = ?(d.contains(" ")):true:false;
if(a)
{
Console.WriteLine(" " + d);
}
Console.Read();
So what is that you are really after? If you want to make sure that something has hit for damage (in this case), why are you not using string.Format
string a = string.Format("You hit someone for {d} damage", damage);
In this way, you have the ability to have the damage qualifier that you are looking for, and are able to calculate that for other parts.