Swift – String Length/Count
In this tutorial, we will learn to find the length of string in Swift programming.
To get the length of a String in Swift, use count
property of the string.
</>
Copy
string.count
count property is an integer value representing the number of characters in this string.
Example 1 – String length
In the following example, we take a string in variable str
and find its length using count
property.
main.swift
</>
Copy
var str = "Hello World"
var len = str.count
print( "Length of str is \(len)" )
Output
Length of str is 11
Conclusion
In this Swift Tutorial, we have learned to get the length of a String using count property with the help of Swift example programs.