I am trying to check whether a string contains a specific string or not.
Briefly, here is my code (which is a small part of the program where I omitted irrelevant codes) :
string y = someValue;
for(string x in someCollection)
{
if (x.Contains(y))
{
Debug.WriteLine(x + " Contains " + y);
}
else
{
Debug.WriteLine(x + " Does Not Contain " + y);
}
}
However, this is what I get as the result:
"Alligator" Contains "Alligator"
"Loves" Does Not Contain "Love"
"To Eat You" Does Not Contain "You"
So, how come!?! Contains() returns true only when both strings are the exact matches?? Something is not right here...
ps. the string x and y were read from a text file and have been through some text cutting process, if that would help...
Your output is correct. Your expectation is wrong. Your confusion is over the quote characters. "Loves"
really does not contain "Love"
, but it does contain "Love
.
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