如何将Char转换为Julia中的字符串?
问题描述:
在茱莉亚,Char和String不具有可比性。如何将Char转换为Julia中的字符串?
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"