Skip to content

Instantly share code, notes, and snippets.

@gorrotowi
Created July 12, 2016 18:26
Show Gist options
  • Save gorrotowi/22e6b109470b9ee5ffe0901aedcd9035 to your computer and use it in GitHub Desktop.
Save gorrotowi/22e6b109470b9ee5ffe0901aedcd9035 to your computer and use it in GitHub Desktop.
This script converts all the first letter of a string to capitalized
func _Dash(text:String) -> String {
var modifiedText = ""
let textArr = text.componentsSeparatedByString(" ")
var repleacetxt = ""
for word in textArr {
if word != "" {
let character = word[word.startIndex]
let scalar = String(character).unicodeScalars
let unicode = scalar[scalar.startIndex].value
if unicode >= 97 && unicode <= 122 {
repleacetxt = word.stringByReplacingCharactersInRange(word.startIndex..<word.startIndex.successor(), withString: String(word[word.startIndex]).capitalizedString)
modifiedText = modifiedText + repleacetxt + " "
} else if unicode == 225 || unicode == 233 || unicode == 237 || unicode == 243 || unicode == 250 {
repleacetxt = word.stringByReplacingCharactersInRange(word.startIndex..<word.startIndex.successor(), withString: String(word[word.startIndex]).capitalizedString)
modifiedText = modifiedText + repleacetxt + " "
} else {
modifiedText = modifiedText + word + " "
}
}
}
return modifiedText.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment