gpt4 book ai didi

swift - 如何解决字符串大写问题

转载 作者:行者123 更新时间:2023-11-28 06:13:37 25 4
gpt4 key购买 nike

我的目标很简单:

enter image description here

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com