4

I've got a little problem. I want to split a String in an array of characters, where I can work on each character.

For example:

"Hello"
    arrayofstring[0] ->H
    arrayofstring[1] ->e
    arrayofstring[2] ->l
    arrayofstring[3] ->l
    arrayofstring[4] ->o

I am thankful for every help.

thor
  • 21,418
  • 31
  • 87
  • 173
MisterMushn
  • 71
  • 2
  • 10
  • Just a friendly tip, you may want to read over this page: [The How-To-Ask Guide](https://stackoverflow.com/help/how-to-ask) so you can always be sure that your questions are easily answerable and as clear as possible. Be sure to include any efforts you've made to fix the problem you're having, and what happened when you attempted those fixes. Also don't forget to your code and any error messages! – Matt C Apr 04 '16 at 03:03

2 Answers2

11

Unless I'm missing something, it's easier than either of the other answers:

let arrayofstring = Array("Hello".characters)
Aaron Rasmussen
  • 13,082
  • 3
  • 42
  • 43
-1

Do something like this:

    let string : String = "Hello"
    let arrayofstring = string.characters.map { (Character) -> Character in
      return Character
    } 
   println(arrayofstring)
Muzahid
  • 5,072
  • 2
  • 24
  • 42