Julia 字符数组到字符串

Met*_*lon 2 arrays string type-conversion julia

这似乎是一件非常明显的事情,但我找不到解决方案。我试过:

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

string(array)
# -> "['U']"
Run Code Online (Sandbox Code Playgroud)

显然没有人达到我想要达到的目标。


我的整个代码如下所示:

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
Run Code Online (Sandbox Code Playgroud)

pfi*_*seb 5

你想要实际的String构造函数:

julia> String(['a', 'b', 'c'])
"abc"
Run Code Online (Sandbox Code Playgroud)