This static string will obtain a string in between 2 strings.

For example. I have the string:

Code: 
<a href="myfile.php">foo-bar</a>
If i wanted to get the name of the link (foo-bar):

Code: 
result = GetStringInbetween("\">", "</a>", sourceFile, false, false);
string myString = result[0];
the last two boolean values allow you to choose whether to include your beginning string and ending string with the result.

Code: 

string[] result;

public static string[] GetStringInBetween(string strBegin, string strEnd, string strSource, bool includeBegin, bool includeEnd)
        {
            string[] result = { "", "" };
            int iIndexOfBegin = strSource.IndexOf(strBegin);
            if (iIndexOfBegin != -1)
            {
                if (includeBegin)
                { iIndexOfBegin -= strBegin.Length; }
                strSource = strSource.Substring(iIndexOfBegin
                    + strBegin.Length);
                int iEnd = strSource.IndexOf(strEnd);

                if (iEnd != -1)
                {
                    if (includeEnd)
                    { iEnd += strEnd.Length; }
                    result[0] = strSource.Substring(0, iEnd);
                    if (iEnd + strEnd.Length < strSource.Length)
                    { result[1] = strSource.Substring(iEnd + strEnd.Length); }
                }
            }
            else
            { result[1] = strSource; }
            return result;
        }
jayfella Reviewed by jayfella on . [c#] Get String In between strings This static string will obtain a string in between 2 strings. For example. I have the string: <a href="myfile.php">foo-bar</a> If i wanted to get the name of the link (foo-bar): result = GetStringInbetween("\">", "</a>", sourceFile, false, false); Rating: 5