Updated functions
This commit is contained in:
27
power-query/fReplaceFunction.m
Normal file
27
power-query/fReplaceFunction.m
Normal file
@@ -0,0 +1,27 @@
|
||||
( sInputText as nullable text,
|
||||
optional bWholeCell as nullable logical,
|
||||
optional sTag as nullable text,
|
||||
optional tSubstitution as nullable table) as text =>
|
||||
|
||||
let
|
||||
bIsWholeCell = if (bWholeCell = null) then true else bWholeCell,
|
||||
bIsTagged = not (sTag = null),
|
||||
tSubstitution = if tSubstitution = null then
|
||||
if bIsTagged then
|
||||
try Table.SelectRows(fP("RENAMING_RULES"), each ([#"#"] = sTag)) otherwise fP("RENAMING_RULES")
|
||||
else
|
||||
fP("RENAMING_RULES")
|
||||
else
|
||||
tSubstitution,
|
||||
|
||||
tSubstBuffer = Table.Buffer(tSubstitution),
|
||||
ReplacedText = List.Accumulate(Table.ToRows(tSubstBuffer), sInputText, (state, substitution) =>
|
||||
if bIsWholeCell then
|
||||
if (state = substitution{0}) then
|
||||
substitution{1}
|
||||
else
|
||||
state
|
||||
else
|
||||
Text.Replace(state, substitution{0}, substitution{1}))
|
||||
in
|
||||
ReplacedText
|
||||
Reference in New Issue
Block a user