How to find a word in a string c# code example
Example 1: c# find where word is contained in a string
public static string getBetween(string strSource, string strStart, string strEnd)
{
int Start, End;
if (strSource.Contains(strStart) && strSource.Contains(strEnd))
{
Start = strSource.IndexOf(strStart, 0) + strStart.Length;
End = strSource.IndexOf(strEnd, Start);
return strSource.Substring(Start, End - Start);
}
else
{
return "";
}
}
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: search letters in list c#
The characters of the string are :
w 3 r e s o u r c e . c o m
Example 4: search letters in list c#
Total number of words in the string is : 3