样例1:
let temStr1 = "this is first sentence. this is second sentence."
print(temStr1.capitalized)
This Is First Sentence. This Is Second Sentence.
样例2:
let temStr2 = "this is first sentence. this is second sentence."
print(temStr2.capitalizingFirstLetter())
This is first sentence. This is second sentence.
结论:如果只是标题需要做成样例1,是句子需要做成样例2。
说明:
1. capitalized是swift 系统属性;
2.capitalizingFirstLetter是字体String的拓展方法,如下:
extension String { func capitalizingFirstLetter() -> String { return prefix(1).capitalized + dropFirst() } mutating func capitalizeFirstLetter() { self = self.capitalizingFirstLetter() } }
标签:String,sentence,capitalizingFirstLetter,样例,大写,首字母,second,swift From: https://www.cnblogs.com/akiha/p/16727087.html