" as albert asked Anna, an antelope appeared!" is considered to be one.
private static bool IsAnAlliteration(string subject)
{
bool result = true;
char lead = default(char);
bool inWord = false;
foreach (char c in subject)
{
char current = char.ToLower(c);
bool isLetter = char.IsLetter(current);
// lead contains first character in string
// all words should start with lead character
if (lead == default(char) && isLetter)
lead = current;
if (!inWord && isLetter && lead != current)
result = false; // start of new word, but does not start with lead char
else if (!inWord && isLetter && lead == current)
inWord = true; // start of new word starts with lead char
else if (inWord && char.IsWhiteSpace(current))
inWord = false; // end of word found
if (!result)
break;
}
// did we find at least one word
result &= (lead != default(char));
return result;
}