# Caesar's Cipher (point 14) - Convert array to string

Hi, I’m stuck trying to convert the encrypted array to a string in Caesar’s Chiper point 14. Can anyone please help me understand how I should solve this?

My code:

var alphabet: [Character] = ["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"]
var secretMessageLowercased = secretMessage.lowercased()
var message = Array(secretMessageLowercased)

for i in 0 ..< message.count {
for j in 0 ..< alphabet.count {
if message[i] == alphabet[j] {
message[i] = alphabet[(j + 3) % 26]
break
}
}
}

let encryptedMessage = message
let messageConvertedToString = encryptedMessage.joined()

print("The word you want to chipher is -< \(secretMessage) >-")

print("Your encrypted word is -< \(messageConvertedToString) >-")

Output:

Output:
CaesarCipher.swift:16:49: error: referencing instance method 'joined(separator:)' on 'BidirectionalCollection' requires the types 'String.Element' (aka 'Character') and 'String' be equivalent
let messageConvertedToString = encryptedMessage.joined()
^
Swift.BidirectionalCollection:1:11: note: where 'Self.Element' = 'String.Element' (aka 'Character')
extension BidirectionalCollection where Self.Element == String {
^

Regards,
Fredrik

Couldn’t stop google and found out what I did wrong.

let encryptedMessage = message
let messageConvertedToString = encryptedMessage.joined()

I should write:

let messageConvertedToString = String(message)

Regards,
Fredrik

Hey my code looks just like yours but im still getting an arrayed answer? What am i doing wrong?

// You wrote:
print(message)

// It should be:
print(messageConvertedToString)
1 Like

Ah! Thank you, wondering what was happening with that lol

1 Like