gpt4 book ai didi

string - 如何在 Julia 中将 Char 转换为 String?

转载 作者:行者123 更新时间:2023-12-04 02:01:30 26 4
gpt4 key购买 nike

在 Julia 中,Char 和 String 没有可比性。

julia> 'a' == "a"
false

如何将 Char 值转换为 String 值?

我尝试了以下功能,但它们都不起作用。
julia> convert(String, 'a')
ERROR: MethodError: Cannot `convert` an object of type Char to an object of type String

julia> String('a')
ERROR: MethodError: Cannot `convert` an object of type Char to an object of type String

julia> parse(String, 'a')
ERROR: MethodError: no method matching parse(::Type{String}, ::Char)

最佳答案

办法是

string(c)

例如
julia> string('🍕')
"🍕"
string函数可以将任何内容转换为其字符串表示形式,就像 print 一样编。的确
help?> string
search: string String stringmime Cstring Cwstring RevString readstring

string(xs...)

Create a string from any values using the print function.

julia> string("a", 1, true)
"a1true"

关于string - 如何在 Julia 中将 Char 转换为 String?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42378854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com