How to Get the Length of a String in Swift
In this tutorial, we are going to learn about how to find the length of a given string in Swift language.
Using the count property
To get the length of a string, we can use the built-in count property in Swift.
The
countproperty returns the total number of characters in a string, it is read-only.
Here is an example, that gets the length of a name string:
// the string has 4 characters
let name = "King"
print(name.count)Output:
4Swift version: 5.1


