c# search substring in string code example
Example 1: how to look for substring in string in c#
String phrase = "this is the ultimate string";
Console.WriteLine(phrase.Contains("this"));
Console.WriteLine(phrase.Contains("python"));
Example 2: c# substring find word
public static string GetSubstring(string l_Source, string l_FindCharacter)
{
if (!l_Source.Contains(l_FindCharacter)) return string.Empty;
int End = l_Source.IndexOf(l_FindCharacter, 0) + l_FindCharacter.Length;
return l_Source.Substring(0, End - 1);
}
Example 3: c# find substring in string
string fullName = "John Doe";
bool nameInFullName = fullName.Contains("John");