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

**URL:** https://discourse.julialang.org/t/how-to-convert-1-element-array-string-1-to-string/56317
**Category:** New to Julia
**Created:** [March 2, 2021, 10:45am UTC](https://discourse.julialang.org/t/how-to-convert-1-element-array-string-1-to-string/56317 "2021-03-02T10:45:28Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [March 2, 2021, 10:45am UTC](https://discourse.julialang.org/t/how-to-convert-1-element-array-string-1-to-string/56317/1 "2021-03-02T10:45:28Z")

</div>

Hello,  
I have this array:

```julia
unique(w.Hit)
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
julia> unique(w.Hit)[13:length(unique(w.Hit))]
0-element Array{String,1}
julia> length(unique(w.Hit))
1

```

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

---

<div class="post-metadata">

### Author: ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)
#### Post date: [March 2, 2021, 11:11am UTC](https://discourse.julialang.org/t/how-to-convert-1-element-array-string-1-to-string/56317/2 "2021-03-02T11:11:57Z")

</div>

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].

---

<div class="post-metadata">

### Author: ![fbanning](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fbanning/32/14972_2.png) [@fbanning](https://discourse.julialang.org/u/fbanning)
#### Post date: [March 2, 2021, 11:12am UTC](https://discourse.julialang.org/t/how-to-convert-1-element-array-string-1-to-string/56317/3 "2021-03-02T11:12:17Z")

</div>

> [@Luigi\_Marongiu](#):
>
> unique(w.Hit)

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

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [March 2, 2021, 12:19pm UTC](https://discourse.julialang.org/t/how-to-convert-1-element-array-string-1-to-string/56317/4 "2021-03-02T12:19:04Z")

</div>

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

```julia
unique(w.Hit)[1][13:end]

```

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

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [March 2, 2021, 12:30pm UTC](https://discourse.julialang.org/t/how-to-convert-1-element-array-string-1-to-string/56317/5 "2021-03-02T12:30:24Z")

</div>

Just to complement, since Julia 1.4 we have [`only`](https://docs.julialang.org/en/v1/base/iterators/#Base.Iterators.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.
