# Read ASCII file in Pluto (convert a Vector{UInt} to a Vector{String} similar to readlines)

**URL:** <https://discourse.julialang.org/t/read-ascii-file-in-pluto-convert-a-vector-uint-to-a-vector-string-similar-to-readlines/86591>\
**Category:** Pluto\
**Created:** [August 31, 2022, 11:37am UTC](https://discourse.julialang.org/t/read-ascii-file-in-pluto-convert-a-vector-uint-to-a-vector-string-similar-to-readlines/86591 "2022-08-31T11:37:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [August 31, 2022, 11:37am UTC](https://discourse.julialang.org/t/read-ascii-file-in-pluto-convert-a-vector-uint-to-a-vector-string-similar-to-readlines/86591/1 "2022-08-31T11:37:09Z")

</div>

I am reading data into Pluto from an ASCII file. I note that when I use the PlutoUI command

```julia
@bind name PlutoUI.FilePicker([MIME("text/plain")])

```

that it returns both the file name and the data in some format. What I want is the data from the file. Let’s say we have a file such as

```julia
open("my_file.txt", "w") do io
    write(io, "JuliaLang is a GitHub organization.\nIt has many members.\n");
end

```

we can then read the data using

```julia
readlines(name["name"])

```

which displays in Pluto as

```julia
["JuliaLang is a GitHub organization.", "It has many members."]

```

However this only works in the current working directory, as the file path is not tracked. Since there is also a variable `name["data"]`, I am wondering if I can create a Vector of Strings equivalent to the readlines command from this information?

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [August 31, 2022, 1:24pm UTC](https://discourse.julialang.org/t/read-ascii-file-in-pluto-convert-a-vector-uint-to-a-vector-string-similar-to-readlines/86591/2 "2022-08-31T13:24:13Z")

</div>

More information

```julia
typeof(name["data"])

```

yields

```julia
Vector{UInt8} (alias for Array{UInt8, 1})

```

and

```julia
convert.(Char, name["data"])

```

gives

```julia

'['
'W'
'i'
'n'
more
'\t'
'0'
'\r'
'\n'
'\r'
'\n'

```

I think I can create a function to make this into a vector of Strings like readlines() does, but I also suspect there is a command within Julia that will do this. Will keep looking and appreciate your help.

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [August 31, 2022, 1:48pm UTC](https://discourse.julialang.org/t/read-ascii-file-in-pluto-convert-a-vector-uint-to-a-vector-string-similar-to-readlines/86591/3 "2022-08-31T13:48:47Z")

</div>

More playing around I got it! Eureka!

```julia
filelines = readlines(IOBuffer(name["data"]))

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 31, 2022, 9:39pm UTC](https://discourse.julialang.org/t/read-ascii-file-in-pluto-convert-a-vector-uint-to-a-vector-string-similar-to-readlines/86591/4 "2022-08-31T21:39:42Z")

</div>

You could also use `split(name["data"], '\n')`

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [September 7, 2022, 1:30am UTC](https://discourse.julialang.org/t/read-ascii-file-in-pluto-convert-a-vector-uint-to-a-vector-string-similar-to-readlines/86591/5 "2022-09-07T01:30:56Z")

</div>

> [@stevengj](#):
>
> split(name[“data”], ‘\n’)

Hmm, tried it and split does not like a Vector{Uint8}. If I modify it to

```julia
split(string(Char.(name["data"])...), '\n')

```

to convert it to a Vector{Char} and from there to a string, then the split does work.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [September 7, 2022, 4:54am UTC](https://discourse.julialang.org/t/read-ascii-file-in-pluto-convert-a-vector-uint-to-a-vector-string-similar-to-readlines/86591/6 "2022-09-07T04:54:24Z")

</div>

You can directly do `String(name["data"])` which is more efficient because it directly utilizes the memory and doesn’t need to construct intermediates. It also empties the original vector though.
