Check the number of letters in Swift program for beginners

Check the number of letters in Swift program for beginners. This program will print the count of the letters in swift. Here we have used the count method to print the number of letters in the user given statement in the swift programming language. By using the we can count different set of charecters in swift. The output is calculated and produced the result by count keyword in the program.

let a1 = "welcome"
let a2 = "to"
let a3 = "inlarn"
let a4 = "programming website"
print(a1.count)
print(a2.count)
print(a3.count)
print(a4.count)

 

Output:

7

2

6

1

9

What is count in swift programming language

Swift strings can be viewed as a collection of single characters. So, you can use yourString.count to count the number of entries in the characters array to get the length of a string. In Swift, utilise the array’s count function to find out how big it is. Here’s a brief example of how to count the number of elements in an array. array name.count, where array name is the name of the array variable. The size of this array is returned by count, which is an integer value.

What is let in swift

In Swift, the let keyword can be used to construct immutable variables. An immutable variable is a constant that can only be initialised once. The keyword let is used to declare a constant value, which means that once you’ve given it an initial value, you won’t be able to change it. var is used to declare a variable’s value, which you can change as needed.