RadixTree.Tree.MatchingConsecutiveCharacters C# (CSharp) Method

MatchingConsecutiveCharacters() private method

given a string and a node the number of characters that the string and the node's label have in common starting from the first character in each is returned
private MatchingConsecutiveCharacters ( string word, Node curNode ) : int
word string a string that is to be compared with the node's label
curNode Node a node
return int
        private int MatchingConsecutiveCharacters(string word, Node curNode)
        {
            int matches = 0;
            int minLength = 0;

            //see which string is smaller and save it's lenght
            //when cycling throught the two strings we won't go any further than that
            if (curNode.Label.Length >= word.Length)
                minLength = word.Length;
            else if (curNode.Label.Length < word.Length)
                minLength = curNode.Label.Length;

            if(minLength > 0)
                //go throught the two streams
                for (int i = 0; i < minLength; i++)
                {
                    //if two characters at the same position have the same value we have one more match
                    if(word[i] == curNode.Label[i])
                        matches++;
                    else
                        //if at any position the two strings have different characters break the cycle
                        break;
                }
            //and return the current number of matches
            return matches;
        }