# ANN: StringBuilders.jl

**URL:** <https://discourse.julialang.org/t/ann-stringbuilders-jl/9223>\
**Category:** Community\
**Tags:** announcement\
**Created:** [February 21, 2018, 4:05am UTC](https://discourse.julialang.org/t/ann-stringbuilders-jl/9223 "2018-02-21T04:05:03Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![samoconnor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samoconnor/32/1802_2.png) [@samoconnor](https://discourse.julialang.org/u/samoconnor)\
**Post date:** [February 22, 2018, 9:20pm UTC](https://discourse.julialang.org/t/ann-stringbuilders-jl/9223/3 "2018-02-22T21:20:48Z")

</div>

I was thinking about a mutable `AbstractString` type along the lines of [`uio.h: struct iovec`](https://github.com/torvalds/linux/blob/master/include/uapi/linux/uio.h#L17-L21). It would be like a lazy string builder. Rather than allocating new strings, it would just keep a list of the strings that were appended. A new concatenated string would be created by doing `convert(String, ...)`. Or, if the string was written to an `IO` stream, the new string would never need to be created. The `write` function could just write each collected item in turn.

_(My use case is [splicing changes into JSON texts](https://discourse.julialang.org/t/announce-a-different-way-to-read-json-data-lazyjson-jl/9046/9))_

```julia
struct SplicedString
    v::Vector{AbstractString}
end

```

`append!` just adds to the list:

```julia
append!(s::SplicedString, x::AbstractString) = push!(s.v, x)

```

`splice`-ing a `String` creates a `SplicedString` using `SubStrings` of the original string:

```julia
splice(s::AbstractString, i, x::AbstractString) =
    SplicedString([SubString(s, 1, i), x, SubString(s, i+1)])

```

`splice!` would figure out which item in `s.v` contains index `i`, then splice `x` into that item:

```julia
splice!(s::SplicedString, i, x) = ...

```

```julia
write(io::IO, s::SplicedString) = write(io, s.v...)

```

---

_[View the full topic](https://discourse.julialang.org/t/ann-stringbuilders-jl/9223)._
