Last active
November 30, 2017 21:49
-
-
Save ImkeF/3ba0db54a49c1cb5231ed4b2e9996b89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Removes all duplicate separators within a string. If optional "TrimEnds" is set to "yes" the (single remaining) separators will be removed from the start and end as well. | |
(MyText as text, Separator as text, optional TrimEnds as text) as text => | |
let | |
TransformTextToList = List.Buffer(Text.ToList(MyText)), | |
Result = List.Accumulate(TransformTextToList, // List that will be iterated through | |
"", // a starting value (if necessary, here we leave it blank) | |
(resultSoFar, current) => if Text.End(resultSoFar,1) = Separator and current = Separator then resultSoFar else resultSoFar¤t // operation that will be performed at each iteration-step | |
), | |
TrimEnd = if TrimEnds = "yes" then Text.TrimStart(Text.TrimEnd(Result, Separator), Separator) else Result | |
in | |
TrimEnd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment