David Seek
David Seek

Reputation: 17152

How to fix issue with String capitalization

My goal is quiet simple:

enter image description here

2 capitalized letters from a Date().

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

}

The problem. The 2 print statements result in:

weekday = Fr
weekday.capitalized = Fr

Same does the label.text. What am I missing? Help is very appreciated.

(Expected of course would be FR)

Upvotes: 1

Views: 52

Answers (1)

rob mayoff
rob mayoff

Reputation: 385998

From the 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.

I think you'd be happier with one of these properties mentioned in the “See Also” section of the same page:

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.

Upvotes: 1

Related Questions