Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a String to an array of characters swift 2.0

I need to convert a string into an array of characters. This work in Swift 1.2 and lower but doesn't since Swift 2.0

var myString = "Hello"
Array(myString)  // ["H", "e", "l", "l", "o"]
like image 744
Maver1ck Avatar asked Jul 21 '15 22:07

Maver1ck


People also ask

How do I split a string into character array in Swift?

To split a string into an array in Swift, use the String. split() function.

How do you make an array of strings in Swift?

To convert an array to string in Swift, call Array. joined() function.

How do you split a string into two parts in Swift?

Swift String split() The split() method breaks up a string at the specified separator and returns an array of strings.


1 Answers

var myString = "Hello"
let characters = [Character](myString.characters)  // ["H","e","l","l","o"]

Hope this helps

like image 53
Matteo Piombo Avatar answered Nov 06 '22 02:11

Matteo Piombo