Skip to content

Instantly share code, notes, and snippets.

@tafo
Created August 2, 2020 08:57
Show Gist options
  • Save tafo/4831b78586e741bf15de964996b2297e to your computer and use it in GitHub Desktop.
Save tafo/4831b78586e741bf15de964996b2297e to your computer and use it in GitHub Desktop.
public bool DetectCapitalUse(string word)
{
if (word.Length == 1) return true;
if (word[0] <= 'Z' && word[1] <= 'Z')
{
for (var i = 2; i < word.Length; i++)
{
if (word[i] <= 'Z') continue;
return false;
}
}
else
{
if (word[1] <= 'Z') return false;
for (var i = 2; i < word.Length; i++)
{
if (word[i] >= 'a') continue;
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment