Julia char array to string

Viewed 235

This seems like a really obvious thing to do, but I couldn't find a solution. I tried:

convert(String, array)
# -> MethodError: Cannot `convert` an object of type Array{Char,1} to an object of type String

and

string(array)
# -> "['U']"

Obviously none achieve what I want to achieve.


My whole code looks like this:

function to_rna(dna)
    assignments = Dict('G' => 'C', 'C' => 'G', 'T' => 'A', 'A' => 'U')
    res = Char[length(dna)]
    for i in 1:length(dna)
        res[i] = assignments[dna[i]]
    end
    return string(res)
end
1 Answers

You want the actual String constructor:

julia> String(['a', 'b', 'c'])
"abc"
Related