How to check repeated letters in a string c#

前端 未结 10 564
太阳男子
太阳男子 2020-12-21 01:39

I am creating a program that checks repeated letters in a string.

For Example:

wooooooooooow
happpppppppy

This is my

10条回答
  •  既然无缘
    2020-12-21 02:07

     public int RepeatedLetters(string word)
            {
                var count = 0;
                for (var i = 0; i < word.Count()-1; i++)
                {
                    if (word[i] == word[i+1])
                    {
                        count++;
                    }
                }
                return count;
            }
    

提交回复
热议问题