I have a string in a variable in a logic app which looks like this 123,456,"A,B,C",789
I want to replace the commas in "A,B,C" portion of the string so I end up with a new value of 123,456,"A B C",789.
I have tried a number of different things:
replace(variables('replaceval'),'*","*','')
replace(variables('replaceval'),'%","%','')
replace(variables('replaceval'),'","','')
but nothing seems to work is there a way to use wild card as the "A,B,C" could be "D,E,F"
3
Answers
In an Azure Logic App, you can use the" Compose" action in combination with a combination of Azure Functions and expressions to remove certain characters from a string using a wildcard. if you want, I will provide you a general step-by-step guide on achieving this.
Alternatively, I have reproduced in my environment with Compose actions and below are the expected results:
Design:
Outputs:
If you want to replace or know what it is in the quotations use below design :
Output:
If you want to replace anything you can use the output of compose 3 and use it replace.
You can use the "split" and "join" functions in combination with a loop to achieve this. Here’s how you can do it step by step:
Initialize a variable to store the modified string: Create a
variable, let’s call it "MyModifiedString," and initialize it to an
empty string.
Split the input string using a comma as the delimiter: Use the
"split" function to split the input string into an array:
Inside the loop, use a "Compose" action to conditionally replace the commas within substrings enclosed in double quotes with spaces.
After the loop, use the "join" function to join the modified substrings back together using commas as the delimiter:
This method will replace the commas within the double-quoted portion of the string with spaces and store the modified string in the "ModifiedString" variable.