Created
July 12, 2016 18:26
-
-
Save gorrotowi/22e6b109470b9ee5ffe0901aedcd9035 to your computer and use it in GitHub Desktop.
This script converts all the first letter of a string to capitalized
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
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