# String(array) destroys the array Bug or Feature?

**URL:** <https://discourse.julialang.org/t/string-array-destroys-the-array-bug-or-feature/29243>\
**Category:** General Usage\
**Tags:** bug\
**Created:** [September 27, 2019, 8:03pm UTC](https://discourse.julialang.org/t/string-array-destroys-the-array-bug-or-feature/29243 "2019-09-27T20:03:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fp4code](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fp4code/32/3083_2.png) [@fp4code](https://discourse.julialang.org/u/fp4code)\
**Post date:** [September 27, 2019, 8:03pm UTC](https://discourse.julialang.org/t/string-array-destroys-the-array-bug-or-feature/29243/1 "2019-09-27T20:03:55Z")

</div>

```julia
a = Array{UInt8,1}(['a','b','c'])
length(a) # 3
s = String(a) # "abc"
length(a) # 0 Bug or feature ?

```

Same behaviour with julia-1.0.5, -1.2, -1.4.0-DEV.152

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [September 27, 2019, 8:19pm UTC](https://discourse.julialang.org/t/string-array-destroys-the-array-bug-or-feature/29243/2 "2019-09-27T20:19:16Z")

</div>

It’s documented in the help text for `String`, so it’s a feature:

```julia
help?> String
search: String string StringIndexError Cstring Cwstring bitstring randstring SubString include_string setrounding unsafe_string AbstractString escape_string

  String(v::AbstractVector{UInt8})

  Create a new String object from a byte vector v containing UTF-8 encoded characters. If v is Vector{UInt8} it will be truncated to zero length and future
  modification of v cannot affect the contents of the resulting string. To avoid truncation use String(copy(v)).

  When possible, the memory of v will be used without copying when the String object is created. This is guaranteed to be the case for byte vectors returned by
  take! on a writable IOBuffer and by calls to read(io, nb). This allows zero-copy conversion of I/O data to strings. In other cases, Vector{UInt8} data may be
  copied, but v is truncated anyway to guarantee consistent behavior.

```

---

<div class="post-metadata">

**Author:** ![fp4code](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fp4code/32/3083_2.png) [@fp4code](https://discourse.julialang.org/u/fp4code)\
**Post date:** [September 27, 2019, 8:24pm UTC](https://discourse.julialang.org/t/string-array-destroys-the-array-bug-or-feature/29243/3 "2019-09-27T20:24:51Z")

</div>

Thanks a lot! It is strange to have something changing the argument without the ! suffix. Isn’t it ?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [September 27, 2019, 8:33pm UTC](https://discourse.julialang.org/t/string-array-destroys-the-array-bug-or-feature/29243/4 "2019-09-27T20:33:21Z")

</div>

Yeah, agreed. It may just be a historical artifact.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [September 27, 2019, 9:11pm UTC](https://discourse.julialang.org/t/string-array-destroys-the-array-bug-or-feature/29243/5 "2019-09-27T21:11:21Z")

</div>

See:  
[https://github.com/JuliaLang/julia/issues/32528](https://github.com/JuliaLang/julia/issues/32528)

---

<div class="post-metadata">

**Author:** ![fp4code](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fp4code/32/3083_2.png) [@fp4code](https://discourse.julialang.org/u/fp4code)\
**Post date:** [September 27, 2019, 9:14pm UTC](https://discourse.julialang.org/t/string-array-destroys-the-array-bug-or-feature/29243/6 "2019-09-27T21:14:12Z")

</div>

Thank!
