find the length of a string in swift

To find the length of a string in Swift, you can use the count property of the string or the countElements() function.

Here's an example using count:

main.swift
let myString = "Hello, World!"
let length = myString.count
print(length) // prints 13
86 chars
4 lines

And here's an example using countElements():

main.swift
let myString = "Hello, World!"
let length = countElements(myString)
print(length) // prints 13
95 chars
4 lines

Both methods will give you the length of the string, which in this case is 13.

gistlibby LogSnag