# How to parse vector/array of string?

**URL:** <https://discourse.julialang.org/t/how-to-parse-vector-array-of-string/1494>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 15, 2017, 12:12pm UTC](https://discourse.julialang.org/t/how-to-parse-vector-array-of-string/1494 "2017-01-15T12:12:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![programista](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/programista/32/5372_2.png) [@programista](https://discourse.julialang.org/u/programista)\
**Post date:** [January 15, 2017, 12:12pm UTC](https://discourse.julialang.org/t/how-to-parse-vector-array-of-string/1494/1 "2017-01-15T12:12:34Z")

</div>

How to parse vector/array of string ?  
julia\> HH\_baza[1,4]  
“4385.37”

julia\> parse(Float64,HH\_baza[1,4])  
4385.37

julia\> parse(Float64,HH\_baza[:,4])  
ERROR: MethodError: `parse` has no method matching parse(::Type{Float64}, ::Array{UTF8String,1})  
Closest candidates are:  
parse{T\<:AbstractFloat}(::Type{T\<:AbstractFloat}, ::AbstractString)

julia\> typeof(HH\_baza[1,4])  
UTF8String

julia\> eltype(HH\_baza[1,4])  
Char

julia\>  
Paul

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 15, 2017, 12:16pm UTC](https://discourse.julialang.org/t/how-to-parse-vector-array-of-string/1494/2 "2017-01-15T12:16:20Z")

</div>

Use an array comprehension.  
In 0.6 (and maybe 0.5) you can use . (broadcast)

---

<div class="post-metadata">

**Author:** ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)\
**Post date:** [January 15, 2017, 12:21pm UTC](https://discourse.julialang.org/t/how-to-parse-vector-array-of-string/1494/3 "2017-01-15T12:21:21Z")

</div>

> [@dpsanders](#):
>
> In 0.6 (and maybe 0.5) you can use . (broadcast)

broadcast doesn’t work here in 0.5

```julia
julia> parse.(Float64, ["122.3", "19990.2"])
ERROR: MethodError: no method matching size(::Type{Float64})

```

As @dpsanders suggested, array comprehensions should do the trick

```julia
julia> [parse(Float64, x) for x in ["122.3","433.2"]]
2-element Array{Float64,1}:
 122.3
 433.2

```

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 15, 2017, 12:23pm UTC](https://discourse.julialang.org/t/how-to-parse-vector-array-of-string/1494/4 "2017-01-15T12:23:17Z")

</div>

On 0.5, there is a sneaky trick that I learnt today: wrap the first argument in square brackets:

```julia
julia> x = ["3.1", "-17.2"]
2-element Array{String,1}:
 "3.1"
 "-17.2"

julia> parse.([Float64], x)
2-element Array{Float64,1}:
   3.1
 -17.2

```

On 0.6, it’s just

```julia
julia> parse.(Float64, x)

```
