by @CodingExample

How to get the length of a string in Swift

Home » swift » How to get the length of a string in Swift

In swift, strings can be treated as an array so that we can get the length of a string by using string.count property.

Example:

 // the string has 4 characters
let name = "King"

print(name.count) // output is 4

Swift version: 5.1