Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created July 29, 2023 13:24
Show Gist options
  • Select an option

  • Save foxicode/741bc85a8a5f6a1b7418d493b91c2f8b to your computer and use it in GitHub Desktop.

Select an option

Save foxicode/741bc85a8a5f6a1b7418d493b91c2f8b to your computer and use it in GitHub Desktop.
Capitalizing first letter in String (Swift)
public extension String {
var withFirstCapitalized: String {
if isEmpty {
return self
}
let first = substring(start: 0, length: 1)
let other = count > 1 ? self.substring(start: 1, length: count - 1) : ""
return "\(first.uppercased())\(other)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment