Skip to content

Instantly share code, notes, and snippets.

@jquave
Created July 4, 2015 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquave/a7169736faa0588a63db to your computer and use it in GitHub Desktop.
Save jquave/a7169736faa0588a63db to your computer and use it in GitHub Desktop.
import Foundation
extension String {
func numsToCharsA() -> String {
return self.stringByReplacingOccurrencesOfString("1", withString: "a")
.stringByReplacingOccurrencesOfString("2", withString: "b")
.stringByReplacingOccurrencesOfString("3", withString: "c")
.stringByReplacingOccurrencesOfString("4", withString: "d")
.stringByReplacingOccurrencesOfString("5", withString: "e")
.stringByReplacingOccurrencesOfString("6", withString: "f")
.stringByReplacingOccurrencesOfString("7", withString: "g")
.stringByReplacingOccurrencesOfString("8", withString: "h")
.stringByReplacingOccurrencesOfString("9", withString: "i")
}
func numsToCharsB() -> String {
let table = [
"1":"a",
"2":"b",
"3":"c",
"4":"d",
"5":"e",
"6":"f",
"7":"g",
"8":"h",
"9":"i"
]
var newStr = self
for (key, value) in table {
print("value: \(value), key: \(key)")
newStr = newStr.stringByReplacingOccurrencesOfString(key, withString: value)
}
return newStr
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment