# Grouping vector of strings by left - right context

**URL:** <https://discourse.julialang.org/t/grouping-vector-of-strings-by-left-right-context/62907>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 14, 2021, 7:49pm UTC](https://discourse.julialang.org/t/grouping-vector-of-strings-by-left-right-context/62907 "2021-06-14T19:49:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![djholiver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djholiver/32/50470_2.png) [@djholiver](https://discourse.julialang.org/u/djholiver)\
**Post date:** [June 14, 2021, 7:49pm UTC](https://discourse.julialang.org/t/grouping-vector-of-strings-by-left-right-context/62907/1 "2021-06-14T19:49:09Z")

</div>

Hi,

I have seen a few example approaches (covert to DataFrame, write your [own](https://discourse.julialang.org/t/splitting-an-array-of-strings/16634)), but can’t quite get my scenario to work.

I have a vector of strings with a character to split on that maps to the vector of “columns” (separated like this to reduce redundancy) and what I want to achieve is a grouped output about each of the “columns”. E.G:

```julia
struct ColumnSetQuery <: IQueryModel
    columnSet :: Vector{String}
    argSeperator :: String
    wildCard :: String
    querySet :: Vector{String}
end
StructTypes.StructType(::Type{ColumnSetQuery}) = StructTypes.Struct()

argSeperator = "-"
wildCard = "?"
columnSet = ["name","surname","region"]
querySet = ["AD-FR-FR","AD-FR-AN","AD-FG-?","AP-FG-?", "AP-DR-PQ","AP-FR-FR"]

```

What I want to achieve is something like:

```julia
groupBy(querySet) = [["AD","FR",{"FR","AN"}],["AD","FG","?"],["AP",{"FG","DR"},"PQ"], ["AP","FR","FR"]]

```

note that I use {} to describe the problem better (I hope) rather than and that, by virtue of “AD-FR-FR” already being grouped, it doesn’t then end up grouped into “AP-FR-FR” e.g. [{“AD”,“AP”},“FR”,“FR”] (which is purely due to the order encountered and to mitigate duplication).

I tried foldl, groupby from [SplitApplyCombined.jl](https://github.com/JuliaData/SplitApplyCombine.jl) but haven’t got it working.

Any help would be appreciated.

Regards,
