1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| let
RemoveAny = (Source as text, Searched as text) as text =>
let
positions = Text.PositionOf(Source, Searched, Occurrence.All, Comparer.OrdinalIgnoreCase),
indexes = {1 .. List.Count(positions) - 1},
positions2 = List.InsertRange(
List.Transform(indexes, (indx) => positions{indx} - (indx * Text.Length(Searched))),
0, {positions{0}}
),
concat = if List.Count(positions2) > 1
then
List.Accumulate(positions2, Source, (state, current) => Text.ReplaceRange(state, current, Text.Length(Searched), ""))
else
Text.ReplaceRange(Source, positions{0}, Text.Length(Searched), "")
in concat
in
RemoveAny |
Partager