Created
February 1, 2019 15:14
-
-
Save NickHung1982/7e55ed93e3d1d1a9fcd0807bff9ae6d7 to your computer and use it in GitHub Desktop.
ConvertStringToArray
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 splitCapitalString(_ textString:String) -> [String] { | |
var newStringArray = [String]() | |
for char in textString { | |
if String(char) == String(char).uppercased() { | |
newStringArray.append(" ") | |
} | |
newStringArray.append(String(char)) | |
} | |
//joined 把加工後的array 變成字串 "HeMoYo" -> " He Mo Yo" | |
//trimmingCharacters 移除左右空白 | |
//compoents 把空白拆開為Array, 也可以用 Split(separator:), 但是會回傳 SubSequence type | |
return newStringArray.joined().trimmingCharacters(in: .whitespacesAndNewLines).compoents(separatedBy: " ") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment