我的目标很简单:
Date()
中的 2 个大写字母。
func getWeekday(booking: ClientBooking) {
let formatter = CoreServices.getDateFormatter()
formatter.dateFormat = "EEEEEE"
let weekday = formatter.string(from: booking.date)
print("weekday = \(weekday)")
print("weekday.capitalized = \(weekday.capitalized)")
self.weekdayLabel.text = weekday.capitalized
}
问题。 2 个打印语句导致:
weekday = Fr
weekday.capitalized = Fr
label.text
也是如此。我错过了什么?非常感谢您的帮助。
(当然应该是 FR
)
最佳答案
来自NSString.capitalized
documentation :
A capitalized string is a string with the first character in each word changed to its corresponding uppercase value, and all remaining characters set to their corresponding lowercase values.
我认为您会对同一页面的“另请参阅”部分中提到的这些属性之一感到满意:
var uppercased: String
An uppercase representation of the string.
var localizedUppercase: String
Returns a version of the string with all letters converted to uppercase, taking into account the current locale.
关于swift - 如何解决字符串大写问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45766982/