I know that there is lots of questions like this out there. But I really couldn't find anything that solved my problem.
I want to check if the string contains the specific input number. See the following example:
public Boolean checkString()
{
string input = "2.5.8.12.30";
string intToFind = "3";
if (input.contains(intToFind))
{
return true;
}
else
{
return false;
}
}
This returns true but I want it to return false since the intToFind string is 3 and not 30. So it is the contains() that is the problem.
How do I make it search for 3 only?
You could use String.Split
+ Contains
:
bool contains3 = input.Split('.').Contains("3");
bool anyThree = input.Split('.').Any(str => str == "3");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With