Advertisement
KonstantyNil

Untitled

Feb 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. static void UberIsPalindrome(string palindrome)
  2.         {
  3.             string isPalindrome1 = RemoveAllSpecialCharactersAndLower(palindrome);
  4.             char[] isPalindrome2 = isPalindrome1.ToCharArray();
  5.             Array.Reverse(isPalindrome2);
  6.             Console.WriteLine((isPalindrome1 == string.Join("", isPalindrome2) ? true : false));
  7.         }
  8.  
  9.         static string RemoveAllSpecialCharactersAndLower(string testStr)
  10.         {
  11.             string str = testStr.ToLower();
  12.             char[] buffer = new char[str.Length];
  13.             int indx = 0;
  14.  
  15.             foreach (char c in str)
  16.             {
  17.                 if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z'))
  18.                 {
  19.                     buffer[indx] = c;
  20.                     indx++;
  21.                 }
  22.             }
  23.  
  24.             return new string(buffer, 0, indx);
  25.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement