Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the length of a String in Swift 2.0?

Tags:

So far it was:

let string = "my example string"
if count(string) >= 3 { ... }

But now I get an error:

count is unavailable: access the count property on the collection. Type String doesn't conform to protocol CollectionType

like image 934
Bartłomiej Semańczyk Avatar asked Jun 26 '15 09:06

Bartłomiej Semańczyk


People also ask

How do I get the length of a string in Swift?

Swift – String Length/Count 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.

How do you check a length of a string?

To calculate the length of a string in Java, you can use an inbuilt length() method of the Java string class. In Java, strings are objects created using the string class and the length() method is a public member method of this class.

What is the length of a string?

The length or size of a string means the total number of characters present in it. For Example: The string “Geeks For Geeks” has 15 characters (including spaces also).


1 Answers

Oh, it is simple:

string.characters.count

like image 151
Bartłomiej Semańczyk Avatar answered Nov 11 '22 15:11

Bartłomiej Semańczyk