How to convert only the first character to uppercase in a string in Swift?

1 · Ram · Sept. 8, 2024, 12:39 p.m.
In Swift, you can make the first character of a string uppercase by using built-in string manipulations or by extending the String type. Here’s an example of both approaches: 1. Simple Inline Approach: You can capitalize the first character like this: let lowercaseString = "hello world" let capitalizedString = lowercaseString.prefix(1).capitalized + lowercaseString.dropFirst() print(capitalizedString) // "Hello world" 2. Using a String Extension: You can create a String extension to make it reu...