Parser.ParserBase.CountStringsBefore C# (CSharp) Method

CountStringsBefore() public static method

Returns how many continuous specified strings are before of the specified position in the specified text
public static CountStringsBefore ( string text, int position, string @string ) : int
text string
position int
@string string
return int
        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;
        }