skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. Alternatively, I have reproduced in my environment with Compose actions and below are the expected results:

    Design:

    replace(replace(replace(outputs('Compose'),split(replace(outputs('Compose'),'"','{'), '{')[1],''),'"',''),',,',',')
    

    enter image description here

    Outputs:

    enter image description here

    If you want to replace or know what it is in the quotations use below design :

    split(replace(outputs('Compose'),'"','{'), '{')[1]
    

    enter image description here

    Output:

    enter image description here

    If you want to replace anything you can use the output of compose 3 and use it replace.

    Login or Signup to reply.
  3. 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:

    1. Initialize a variable to store the modified string: Create a
      variable, let’s call it "MyModifiedString," and initialize it to an
      empty string.

    2. Split the input string using a comma as the delimiter: Use the
      "split" function to split the input string into an array:

    split(variables('InputString'), ',')
    
    1. Iterate through the Substrings:Use a "For each" loop to iterate through the array of substrings.Replace Commas within Quoted Substrings:
      Inside the loop, use a "Compose" action to conditionally replace the commas within substrings enclosed in double quotes with spaces.
        If(
            startsWith(item(), '"'),
            replace(item(), ',', ' '),
            item()
        )
    
    1. Join the modified substrings back together using commas as the delimiter:
      After the loop, use the "join" function to join the modified substrings back together using commas as the delimiter:
        join(outputs('For_each'), ',')
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search