Binary values in strings

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.

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

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

1 Like

This thread is off-topic.