Skip to content

Instantly share code, notes, and snippets.

@jweinst1
Created July 13, 2015 19:27
Show Gist options
  • Save jweinst1/bacf35f221688d4635b1 to your computer and use it in GitHub Desktop.
Save jweinst1/bacf35f221688d4635b1 to your computer and use it in GitHub Desktop.
In Swift, Takes a string and returns the nth character from the end, where 0 is the last character in the string.
// Takes a string and returns the nth character from the end, where 0 is the last character in the string.
func reversestrindex(str: String, index: Int) ->Character {
var reversedstrArray = Array(reverse(str))
return reversedstrArray[index]
}
reversestrindex("power", 2)
// "w"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment