Power Automate Exchange

Please login or click SIGN UP FOR FREE to create your FlowUG account to join this user group.
Expand all | Collapse all

Remove double quotes in a string

  • 1.  Remove double quotes in a string

    Bronze Contributor
    Posted Apr 28, 2021 10:12 AM
    Hello,

    I'm looking for a way to remove a the double quotes in a string. For example, if the sting is:

    Then he stated, "We don't need any of this".

    How would I remove the double quotes on each side? Thank you for your help.

    ------------------------------
    Tristan Holt
    CRM Administrator
    Professional Plumbing Group
    ------------------------------


  • 2.  RE: Remove double quotes in a string

    Top Contributor
    Posted Apr 29, 2021 01:07 AM

    Option 1: Remove any double quotes in a text string with replace('my string','"',''). This will substitute any instance of a double quote anywhere in the string with an empty string.

    Option 2: Remove the first and last character in a string with substring('my string',1,sub(length('my string'),2)). This will remove the first and last characters from any string that is two or more characters long. If the input string is too short you may need to add an if() such as if(less(length('my string'),2),'my string',substring('my string',1,sub(length('my string'),2))) so you don't feed too a short a string into the substring formula.

    Option 3: Remove the first and last character in a string only if they are double quotes:

    Step 1:
      if(equals(substring('my string',0,1),'"'),substring('my string',1),'my string')

    Step 2:

    if(equals(substring('Step 1',sub(length('Step 1'),1)),'"'),substring('Step 1',sub(length('Step 1'),1)),'Step 1')

    'my string' is the dynamic content of the string you're looking for and in the case of option 3, 'Step 1' is the output of a compose in which you did step 1

    If this is in a Select or another action that acts on a collection you would need to roll steps 1 and 2 into one expression, which would get quite long.

    if(equals(substring(if(equals(substring('my string',0,1),'"'),substring('my string',1),'my string'),sub(length(if(equals(substring('my string',0,1),'"'),substring('my string',1),'my string')),1)),'"'),substring(if(equals(substring('my string',0,1),'"'),substring('my string',1),'my string'),sub(length(if(equals(substring('my string',0,1),'"'),substring('my string',1),'my string')),1)),if(equals(substring('my string',0,1),'"'),substring('my string',1),'my string'))

    I haven't tested this, apologies if you get errors. If you genuinely need help debugging this I can make it go in a flow and post the working expressions.



    ------------------------------
    Will Page
    Technical consultant
    Christchurch, NZ
    ------------------------------



  • 3.  RE: Remove double quotes in a string

    Bronze Contributor
    Posted Apr 29, 2021 12:06 PM

    Hey Will,

     

    Thanks for responding so quickly. I did try option 1 and for some reason, it totally ignores the double quotes in the string. In this one instance, the double quotes are in the middle of the string. The string is a dynamics field that is coming from the notes field of a phone call in D365CE. I need to clean out any double quotes that a user in D365CE puts in the notes of a phone call activity because having double quotes in the string causes an outgoing email adaptive card to be blank when the string has double quotes. I don't know if I can use the other options because the position that the double quotes show up will always be different.

     

     






  • 4.  RE: Remove double quotes in a string

    Top Contributor
    Posted Apr 29, 2021 03:02 PM
    Double quotes can be tricky like that. Use a Compose action first and type a double quote into it, then next substitute the double quote in your string like substitute('my string', outputs('Compose'),'')

    That's two single quotes (an empty string) as the third parameter of substitute() but you can use any character.

    I've done exactly the same thing to handle double quotes in as string going into an adaptive card, and substituted the double quote with \" which escapes the character and displays it in the adaptive card.

    ------------------------------
    Will Page
    Technical consultant
    Christchurch, NZ
    ------------------------------