1

I have this:

var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

println("You should know your \(alphabet)'s")

How do I access a, b, c?

I've tried \(alphabet[0...3])'s and \(alphabet['0', '1', '2'])'s and \(alphabet[0,1,2)'s to no avail.

What am I missing?

1 Answer 1

3

You were on the right track with alphabet[0..2], but what you were missing is the join function which concatenates strings using a separator:

let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
let section = alphabet[0...2]
let s = join(", ", section) // Separator goes in the ""
println(s) // a, b, c

Also, there is no reason to use var for the alphabet so use let

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! I can't believe the join function isn't mentioned in the array tuts/docs that I've come across, and I've looked at a number of them. I really appreciate it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.