# Split keepempty

**URL:** <https://discourse.julialang.org/t/split-keepempty/117453>\
**Category:** General Usage\
**Tags:** strings\
**Created:** [July 25, 2024, 4:19am UTC](https://discourse.julialang.org/t/split-keepempty/117453 "2024-07-25T04:19:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [July 25, 2024, 4:19am UTC](https://discourse.julialang.org/t/split-keepempty/117453/1 "2024-07-25T04:19:19Z")

</div>

What does `keepempty` mean in `split`? Is there a good example?

> • keepempty: whether empty fields should be kept in the result. Default is false without a dlm argument, true with a dlm argument.

```julia
julia> split("hello;there;user;;;foo", ";"; limit=4, keepempty=false)
4-element Vector{SubString{String}}:
 "hello"
 "there"
 "user"
 ";;foo"

```

---

<div class="post-metadata">

**Author:** ![screw\_dog](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/screw_dog/32/48119_2.png) [@screw\_dog](https://discourse.julialang.org/u/screw_dog)\
**Post date:** [July 25, 2024, 4:57am UTC](https://discourse.julialang.org/t/split-keepempty/117453/2 "2024-07-25T04:57:27Z")

</div>

In your example it’s not obvious what the difference is between `keepempty=false` and `true` because the empty fields occur after the 4th split and you have `limit=4`. Removing this we can see:

```julia
julia> split("hello;there;user;;;foo", ";"; keepempty=true)
6-element Vector{SubString{String}}:
 "hello"
 "there"
 "user"
 ""
 ""
 "foo"

julia> split("hello;there;user;;;foo", ";"; keepempty=false)
4-element Vector{SubString{String}}:
 "hello"
 "there"
 "user"
 "foo"

```

Essentially, if you have two delimiters in a row (ie “;;”) it controls whether to return an empty string or to ignore it.

HTH
