Skip to main content
mollyn6512
September 26, 2022
Question

Remove a list of unwanted characters from a text string

  • September 26, 2022
  • 8 replies
  • 0 views

Hi every one, 

I'm having a text string as example: 

{"Status":"Active","updatedBy":"lynn123","hasAccount":false}

What I expect to have is: 

Status: Active

updatedBy: lynn123

hasAccount: no 

I think for replacing comma with a line-break, char(10) might work, then I will substitute false with "no". But for the rest of characters {,},"", I'm not sure how to remove them all at once. I checked documentary for a!stripWith or a!reject and I think they don't work with a list of characters. 

Hope I can have some suggestions from you,

Thanks a lot!

    8 replies

    stefanhelzle0001
    Brainy
    September 26, 2022

    This looks like a JSON string. Why not just use fromJson() to turn it into a dictionary and then use normal Appian functionality to display the values?

    mollyn6512
    September 26, 2022

    After applying fromJson, I get this string: [Status:Active,updatedBy:,hasAccount:false]. Not sure what is it's data type as I did this in a forEach loop for every row of my grid column. 

    Could you explain more of the normal Appian functions that you mentioned? 
    What I could think of is: 

    substitute(
    stripwith(
    "[Status:Active,updatedBy:,hasAccount:false]","[",
    ),
    ",",
    char(10)
    )

    However stripWith only allow 1 character so I missed the "]", also I couldn't have the line break as expected. 

    The result of my work is: 

    "Status:Active updatedBy: hasAccount:false]"(Text), in which "]" has not yet been removed.

    stefanhelzle0001
    Brainy
    September 26, 2022

    fromJson does NOT return a string, but a dictionary containing key-value pairs. Appian does display it as a string.

    You can then access the fields using dot-notation or index()/property(). Check the Appian documentation for how to do this.

    September 26, 2022

    As Stefen Suggested, Use fromJson and then use index functionality to get the particular value based on the key.

    mollyn6512
    September 26, 2022

    Thanks Deepak, the problem is that I need to apply the functions to all rows in a forEach loop, and not all of them have the same index for those characters to use index function :(

    ajk0002
    September 26, 2022

    Hi [mention:b18d9a2f367a407ca0cf8a9b71bef972:e9ed411860ed4f2ba0265705b8793d05],

    below snippet might helpful for your case

    substitute(
    stripwith(
    tostring(
    {
    "Status": "Active",
    "updatedBy": "lynn123",
    "hasAccount": false
    }
    ),
    "[]"
    ),
    ",",
    char(10)
    )