简体   繁体   English

Julia 字符数组到字符串

[英]Julia char array to string

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

You want the actual String constructor:您需要实际的String构造函数:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM