how to get string between two strings in c#
how to get string between two strings in c#
Example:
string source="one two three four five"
If you want to get strins between "one" and "five" then use this function call
string temp = GetStringBetween("one ", "five", source);
And the copy the following function & paste in your program.
public static string GetStringBetween(string strbegin, string strend, string source)
{
int iIndexOfBegin = source.IndexOf(strbegin) + strbegin.Length;
string s1 = source.Substring(iIndexOfBegin);
int iIndexOFfEnd = s1.IndexOf(strend);
string s2 = s1.Substring(0, iIndexOFfEnd);
return s2;
}
Output:
"two three four"
Comments
Post a Comment