I'm trying to add a String to an array, as follows:
arry = String[]
append!(arry, "test")
but I'm getting the following error:
Cannot `convert` an object of type Char to an object of type String
Why am I getting this error when I'm adding a String, not a Char?
(posting my own answer below for the benefit of other Julia newbies - anyone with more helpful tips please jump in!)
I cannot see your answer, but here is a typical pattern.
You can push! a single element or append! a collection:
julia> arry = String[]
0-element Array{String,1}
julia> push!(arry, "test")
1-element Array{String,1}:
"test"
julia> append!(arry, ("test",))
2-element Array{String,1}:
"test"
"test"
julia> append!(arry, ["test"])
3-element Array{String,1}:
"test"
"test"
"test"
julia> append!(arry, Ref("test"))
4-element Array{String,1}:
"test"
"test"
"test"
"test"
Note that a collection can be e.g. a Tuple, a Vector or Ref (which is kind of 0-dimensional and non-allocating collection that is often encountered in broadcasting).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With