Line splitting in quick

var password : string = "F36fjueEA5lo903" 

I need to separte this character by character.

something like that.

 var 1character : string = "F" var 2character : string = "3" var 3character : string = "6" 

. ,.

PD: I'm new

+5
source share
2 answers

You can do it with

 let characters = Array(password) 

With this, you have an array of characters in a String. You can assign it to other variables if you wish.

+6
source

While you can do this, as Jacobson showed you in his answer (excellent), you should not save the letters manually in your own variables. Because you often don’t know the password length. So what you can do is repeat your characters:

 for letter in yourString{ //do something with the current letter var yourCurrentLetter = letter println(yourCurrentLetter)//a then s, d, f etc. } 
+1
source

All Articles