One way to capitalise the first letter of a string in Swift is to use the capitalized
property provided by the String
class. Here is an example:
main.swift112 chars4 lines
Another way is to use the prefix(1)
method to get the first letter, then use the uppercased()
method to convert it to uppercase, and finally concatenate it with the rest of the string:
main.swift195 chars6 lines
Both of these approaches will result in a string with the first letter capitalized.
gistlibby LogSnag