How to convert 1-element Array{String,1} to string?

I have this array:

1-element Array{String,1}:
 "AC_000006.1 Human adenovirus D"

I would like to get the letters from position 13 to the end but:

julia> unique(w.Hit)[13:length(unique(w.Hit))]
0-element Array{String,1}
julia> length(unique(w.Hit))

How can I convert unique(w.Hit) into a string?

You need to simply extract the string from your Array, then apply the indexing as above.
If your w.Hit is always a 1-element Array, you can get your string as x=w.Hit[1].

1 Like

You could just do unique(w.Hit)[1] if that fits your usecase.

1 Like

And then, when indexing from position 13 to the end, you just write:


There is no need to calculate length(unique(w.Hit)), which does a lot of unnecessary extra work, and will be slow.

Just to complement, since Julia 1.4 we have only (you do not need to import anything) that takes the only element of a collection and return it, throwing an exception if the collection has zero or more than one element.

1 Like