# Binary values in strings

**URL:** https://discourse.julialang.org/t/binary-values-in-strings/11308
**Category:** Offtopic
**Created:** [May 30, 2018, 6:17pm UTC](https://discourse.julialang.org/t/binary-values-in-strings/11308 "2018-05-30T18:17:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [May 30, 2018, 6:17pm UTC](https://discourse.julialang.org/t/binary-values-in-strings/11308/1 "2018-05-30T18:17:43Z")

</div>

> [@Problem processing non utf8 string](https://discourse.julialang.org/t/problem-processing-non-utf8-string/11261/4):
>
> That was my problem with Julia from the start with the lack of any “BinaryString” type, and the issue that if you used `Vector{UInt8}` , you couldn’t even use the string operations for concatenation (’\*’).

If _this_ was your problem, that did not come across very clearly. Julia does have a binary string type these days: it’s called `String` and it can hold arbitrary binary data, interpreted as UTF-8 to the extent possible.

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [May 30, 2018, 11:17pm UTC](https://discourse.julialang.org/t/binary-values-in-strings/11308/2 "2018-05-30T23:17:22Z")

</div>

> [@Problem processing non utf8 string](https://discourse.julialang.org/t/problem-processing-non-utf8-string/11261/6):
>
> If _this_ was your problem, that did not come across very clearly.

Shall I go and point out where I discussed this on GitHub 3 years ago?  
It was one of the issues I had with using `*` for string concatenation, b"xxxx" looked like it should produce a binary string, but it returned a `Vector{UInt8}` instead, and `Vector{UInt8}` can’t be used with string functions, and `*` gave very strange results. (and it’s still the case on master:)

```julia
julia> b"1234" * b"5678"
ERROR: DimensionMismatch("Cannot multiply two vectors")
Stacktrace:
 [1] *(::Base.CodeUnits{UInt8,String}, ::Base.CodeUnits{UInt8,String}) at /j/julia/usr/share/julia/stdlib/v0.7/LinearAlgebra/src/deprecated.jl:555
 [2] top-level scope

```

> [@Problem processing non utf8 string](https://discourse.julialang.org/t/problem-processing-non-utf8-string/11261/5):
>
> Those annoyances are gone on Julia master.

Not really, because if you try to index into a non-UTF-8 string that is stored in a `String`, you’ll get all sorts of problems like the following:

```julia
julia> x[3]
ERROR: StringIndexError("\xffÿ🖖\u1fff\x80\xc0\x80", 3)
Stacktrace:
 [1] string_index_err(::String, ::Int64) at ./strings/string.jl:12
 [2] getindex_continued(::String, ::Int64, ::UInt32) at ./strings/string.jl:215
 [3] getindex(::String, ::Int64) at ./strings/string.jl:208
 [4] top-level scope

```

on top of poor performance.

---

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [May 31, 2018, 8:29pm UTC](https://discourse.julialang.org/t/binary-values-in-strings/11308/3 "2018-05-31T20:29:52Z")

</div>



---

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [May 31, 2018, 8:30pm UTC](https://discourse.julialang.org/t/binary-values-in-strings/11308/4 "2018-05-31T20:30:20Z")

</div>

This thread is off-topic.
