Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kelvinfok/29f1a90976fb85a04ddaaeff9574687e to your computer and use it in GitHub Desktop.
Save kelvinfok/29f1a90976fb85a04ddaaeff9574687e to your computer and use it in GitHub Desktop.
ios-udemy-home String extension
extension String {
var camelCaseToEnglish: String {
var result = ""
var wordStartIndex = self.startIndex
for (index, char) in self.enumerated() {
if index > 0 && char.isUppercase {
let previousWord = self[wordStartIndex..<self.index(self.startIndex, offsetBy: index)]
if !previousWord.isEmpty {
result += "\(previousWord) "
}
wordStartIndex = self.index(self.startIndex, offsetBy: index)
}
}
let lastWord = self[wordStartIndex..<self.endIndex]
if !lastWord.isEmpty {
result += "\(lastWord)"
}
return result
}
var useShortAndFormat: String {
replacingOccurrences(of: "And", with: " & ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment