Case Insensitive Text.Replace In Power Query.

By default Text.Replace do case sensitive replacing. Sometimes we need to do case-insensitive replacement. I have created a custom function that will do the case-insensitive replacing. Here is the function.

(Text as nullable text,Old as text,New as text)=>
let
    // Text = """Hello, world! Hello, World!"", ""World""",
    // Old = "World",
    // New ="Universe",
    StartPositionsOfOldText = List.Reverse(Text.PositionOf(Text,Old,Occurrence.All,Comparer.OrdinalIgnoreCase)),
    ReplacedText = List.Accumulate(StartPositionsOfOldText,Text,(State,Current)=>Text.ReplaceRange(State,Current,Text.Length(Old),New))
in
    ReplacedText

Here is a snapshot of using it:

Leave a Reply

Subscribe to Blog via Email

Enter your email to subscribe to this blog and receive notifications of new posts by email.

You may also like

Please login to Continue Reading