Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Removes text between 2 delimiters.
let func =
(TextToClean as text, StartDelimiter as text, EndDelimiter as text, optional RemoveDelimiters) =>
let
removeDelimiters = if RemoveDelimiters = null then StartDelimiter & EndDelimiter else "",
Source = Text.From(TextToClean),
FirstSplit = List.Buffer( Text.Split(Source, StartDelimiter) ),
Custom2 = if List.First(FirstSplit) = "" then List.Skip(FirstSplit) else FirstSplit,
Custom1 = List.Transform(Custom2, each if Text.Contains(_, EndDelimiter) then Text.AfterDelimiter(_, EndDelimiter, 0) else _),
ListSelect = List.Select(Custom1, each _<>""),
TextCombine = Text.Combine(ListSelect, removeDelimiters)
in
TextCombine,
documentation = [
Documentation.Name = " Text.RemoveBetweenDelimiters ",
Documentation.Description = " Removes text between 2 delimiters. ",
Documentation.LongDescription = " Removes text between 2 delimiters. Option to remove the delimiters as well. Delimters are strings, so can contain multiple characters. ",
Documentation.Category = " Text ",
Documentation.Source = " www.TheBIccountant.com . https://wp.me/p6lgsG-2ak . ",
Documentation.Version = " 2.0 ",
Documentation.Author = " Imke Feldmann: www.TheBIccountant.com. https://wp.me/p6lgsG-2ak . ",
Documentation.Examples = {[Description = " ",
Code = " ",
Result = " "]}]
in
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation))
@ImkeF
Copy link
Author

ImkeF commented Sep 17, 2020

Adjusted for repeating split characters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment