Cool, but you could have also done it with an array: ToCharArray() and Linq (Select & Where)
Here e.g. is the same in Swift; using an array and higher order functions (i.e. similar concept to Linq).
Code:
extension String
{
func isPalindrome() -> Bool {
let lower = self.lowercaseString.unicodeScalars.filter
{ 97...122 ~= Int($0.value) }.map { String($0) }.joinWithSeparator("")
return lower == String(lower.characters.reverse())
}
}
"Noel sees Leon.".isPalindrome() // true
C# Linq version example, hopefully code correct; didn't bother to run it through VS.
Code:
public static bool IsPalindrome(string str)
{
var onlyLetters = str.ToLower().Where(c => Char.IsLetter(c)).ToArray();
return new String(onlyLetters) == new String(onlyLetters.Reverse());
}