var password : string = "F36fjueEA5lo903"
i need separte this character by character.
something like this.
var 1character : string = "F"
var 2character : string = "3"
var 3character : string = "6"
. . .
PD: I am a novice
var password : string = "F36fjueEA5lo903"
i need separte this character by character.
something like this.
var 1character : string = "F"
var 2character : string = "3"
var 3character : string = "6"
. . .
PD: I am a novice
While you can do it like Jacobson showed you in his answer(perfectly fine), you shouldn't save the letters manually in own variables. Because you often don't know the length of the password. So what you could do is iterating over your chars:
for letter in yourString{
//do something with the current letter
var yourCurrentLetter = letter
println(yourCurrentLetter)//a then s, d, f etc.
}
map, but I think your example with a for-loop would be easier to understand. On the other hand, I thought arrays are one of the first basic things a beginner would learn, hence why I showed him how to make an array :) (and thanks)for…in over the string, there’s no need to convert it to an array first, strings conform to SequenceType too.for…in or map or find etc will do the trick