How do I find out if one of my strings occurs in the other in C#?
For example, there are 2 strings: string 1= "The red umbrella"; string 2= "red"; How would I find out if string 2 appears in string 1 or not?
How do I find out if one of my strings occurs in the other in C#?
For example, there are 2 strings: string 1= "The red umbrella"; string 2= "red"; How would I find out if string 2 appears in string 1 or not?
you can use String Contains I guess. pretty sure there is similar question have been asked before How can I check if a string exists in another string
example :
if (stringValue.Contains(anotherStringValue))
{
// Do Something //
}
You can do it like this:
public static bool CheckString(string str1, string str2)
{
if (str1.Contains(str2))
{
return true;
}
return false;
}
Call the function:
CheckString("The red umbrella", "red") => true