Created
July 4, 2015 00:35
-
-
Save jquave/a7169736faa0588a63db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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