public static int CountStringsBefore(string text, int position, string @string)
{
CheckTextAndPositionArguments(text, position);
#region Count the Strings before
int myStringsBeforeCount = 0;
int myPrevPosition = position - @string.Length;
while (myPrevPosition >= 0)
{
// If it is not the specified string prefix
if (string.Compare(text, myPrevPosition, @string, 0, @string.Length, true) != 0)
break;
myStringsBeforeCount++;
myPrevPosition -= @string.Length;
}
#endregion
return myStringsBeforeCount;
}