我有一个包含我的句子的字符串描述,并且只想将第一个字母大写。我尝试了不同的东西,但大多数都给我异常和错误。我正在使用 Xcode 6。
到目前为止,这是我尝试过的:
let cap = [description.substringToIndex(advance(0,1))] as String
description = cap.uppercaseString + description.substringFromIndex(1)
它给了我:
Type 'String.Index' does not conform to protocol 'IntegerLiteralConvertible'
我试过:
func capitalizedStringWithLocale(locale:0) -> String
但我还没有弄清楚如何让它发挥作用。
最佳答案
在 Swift 2 中,你可以这样做
String(text.characters.first!).capitalizedString + String(text.characters.dropFirst())
关于swift - 如何使用Swift将句子的第一个字符大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27082587/