Skip to content

split() enhancement, keep_splitter #20625

@iagobaapellaniz

Description

@iagobaapellaniz

Hello,

I would like to suggest a feature request, which I'm now working on in a new branch, for the split(str, splitter; limit=0, keep=true) function.

I found myself trying to use the function in that way, and what I expect somehow is the following,

julia> split("abcabcdabbcd", "b"; keep_splitter = true)
3-element Array{SubString{String},1}:
 "a"   
 "bca" 
 "bcda"
 "b"
 "bcd"

Should I keep on working? Would it be a breaking change for the rest of the ecosystem?

Some ideas:

  • If the keep_spliter flag is true, then it should not make any difference whether keep (which stands for empty results), is true or false, since, there wouldn't be empty results at all.
  • I'm not sure whether to include some other flag to include the splitter just to the next substring or to the previous one. This is how readlines(file) work, isn't it? In each element of the array we have '\n' at the end.
julia> split("abcabcdabbcd", "b"; keep_splitter = true, prepend = false)
3-element Array{SubString{String},1}:
 "ab"   
 "cab" 
 "cdab"
 "b"
 "cd"

Thanks in advance!

PS, maybe it can be done with another function I don't know yet

Metadata

Metadata

Assignees

No one assigned

    Labels

    collectionsData structures holding multiple items, e.g. setsdesignDesign of APIs or of the language itselfstrings"Strings!"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions