WikiFunctions.Tools.HowMuchStartsWith C# (CSharp) Method

HowMuchStartsWith() public static method

returns how much of the given text starts with only items matched by the given regex, allowing for whitespace only E.g. whether a portion of text starts only with one or more wiki templates
public static HowMuchStartsWith ( string text, Regex Items, bool allowHeading ) : int
text string Article text or section to check
Items System.Text.RegularExpressions.Regex Regex to match one or more items e.g. wiki templates
allowHeading bool Whether to also allow text to start with a heading then only the matched items
return int
        public static int HowMuchStartsWith(string text, Regex Items, bool allowHeading)
        {
            int heading = 0;

            if (allowHeading)
            {
                Match m = WikiRegexes.Headings.Match(text);

                if (m.Index == 0)
                {
                    text = WikiRegexes.Headings.Replace(text, "", 1);
                    heading = m.Length;
                }
            }

            MatchCollection mc = Items.Matches(text);

            if (mc.Count == 0)
                return 0;

            string replaced = ReplaceWithSpaces(text, mc).TrimStart();

            return (text.Length - replaced.Length+heading);
        }
Tools