Last active
May 9, 2018 06:40
-
-
Save ashalva/a2dc0a8d6f79526264aa3e02c2316e52 to your computer and use it in GitHub Desktop.
To lower case implementation in swift.
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 toLowerCase(string: String) -> String { | |
var str = string as NSString | |
for i in 0...(str.length - 1) { | |
if str.character(at: i) >= 65 && str.character(at: i) <= 90 { | |
let changeValue = str.character(at: i) + 32 | |
str = str.replacingCharacters(in: NSMakeRange(i, 1), with: String(Character(UnicodeScalar(changeValue)!))) as NSString | |
} | |
} | |
return str as String | |
} | |
toLowerCase(string: "convErTing StrinG inTo Lower Case") //result "converting string into lower case" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment