Check for repeated characters: csharp


/// Checks for repeated characters
/// Author: http://www.victorbyte.net
/// returns Boolean value

static bool hasDuplicate(string str)
{
   for (int i = 0; i < str.Length; i++)
   { 
       for (int j = i + 1; j < str.Length; j++)
       {                   
           if (str.ElementAt(i) == str.ElementAt(j))
               return true;               
       }       
   }        
   return false;
} 
This entry was posted in Code samples and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *