This static string will obtain a string in between 2 strings.
For example. I have the string:
If i wanted to get the name of the link (foo-bar):
the last two boolean values allow you to choose whether to include your beginning string and ending string with the result.
For example. I have the string:
Code:
<a href="myfile.php">foo-bar</a>
Code:
result = GetStringInbetween("\">", "</a>", sourceFile, false, false);
string myString = result[0];
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;
}