[Solved] Check if string contains only one type of letter C# [closed]


Try this:

private bool ContainsOnlyOneLetter(string String)
    {
        if(String.Length == 0)
        {
            return true;
        }
        for(int i = 0; i < String.Length;i++)
        {
            if(String.Substring(i,1) != String.Substring(0,1))
            {
                return false;
            }
        }
        return true;
    }

And you can use the function like this:

bool containsOneLetter = ContainsOnlyOneLetter("...");

        if (containsOneLetter == true)
        {
            //Put code here when the letters are the same...
        }
        else
        {
            //Code when there are different letters..
        }

1

solved Check if string contains only one type of letter C# [closed]