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.
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
var str = "Hello World" var len = str.count print( "Length of str is \(len)" )
Length of str is 11
In this Swift Tutorial, we have learned to get the length of a String using count property with the help of Swift example programs.