web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Substitute multiple "w...
Power Apps
Answered

Substitute multiple "words" in one string

(1) ShareShare
ReportReport
Posted on by 79

Hi!
Im trying to find a way to replace mutliple words in one string.

For example I have a list with words that I want to replace with "***" in a string, if i had only one replace argument then I could simply use Substitute( "MyString etc and so on", "etc", "***" ). However to replace all words in the string from the list I have to loop throu the list and do "the replace action". 

So for I havent found a solution for this, any one that have any solution? 

 

My main goal is to change mutliple words in one string dynamically. For example:
Input: "This is my source string"
Output: "This **** my **** string"

Categories:
  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @adamtj ,

    Do you mean something like

    ForAll(
     YourListName,
     Substitute(
     YourString,
    	 YourListFieldName,
    	 "***"
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • adamtj Profile Picture
    79 on at

    Hi @WarrenBelz 
    Thank you for replying!
    I tried something like that but it did not change the source string, it returned another list with strings substituted with that current record in the list (the list in the ForAll loop)


    In this example "TempStr" = 'Test string with an e-mail: test@mail.com and and phone: 999-123 45 67.'
    Listitems in "GDPRContent" = 'test@mail.com' and '999-123 45 67'

    UpdateContext({TempStr:{Text: varGdprLeadsNote.NotesHtmlText}});;
    
    UpdateContext({TempCol:
     ForAll(
     Split(varGdprLeadsNote.GDPRContent;";");
     Patch(
     TempStr;
     {
     Text: Substitute(TempStr.Text; ThisRecord.Result; "****")
     }
     )
     )
    })

     

    Above code did not change the source string (TempStr). TempCol however returns a list:

    { Result: "Test string with a e-mail adress: **** and and phone: 999-123 45 67" },
    { Result: "Test string with a e-mail adress: test@mail.com and and phone: ****" }

     

     

  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @adamtj ,

    I am not a fan of either tables stored in Variables or Patching to them (that is what Collections and Collect) are for, however firstly try this

    UpdateContext(
     {
     TempStr:{Text: varGdprLeadsNote.NotesHtmlText}
     }
    );;
    UpdateContext(
     {
     TempCol:
     ForAll(
     Split(
     varGdprLeadsNote,
     GDPRContent & 
     ";"
     ) As aPatch;
     Patch(
     TempStr;
     {
     Text: 
     Substitute(
     TempStr.Text; 
     aPatch.Result; 
     "****"
     )
     }
     )
     )
     }
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • adamtj Profile Picture
    79 on at

    Hi!

    I tried above solution but the results are the same unfortunately.

     

    To clarify the "TempVar" and "TempCol" was only for my troubleshooting, the basic function looks like this:

    ForAll(
     Split(varGdprLeadsNote.GDPRContent;";");
     Substitute(varGdprLeadsNote.NotesHtmlText; ThisRecord.Result; "****")
    )

     

    The problem is that I dont understand how to change the source string "varGdprLeadsNote.NotesHtmlText" to include changes made by the Substitute ForAll loop? The ForAll loop returns multiple strings, one string per item in "Split(varGdprLeadsNote.GDPRContent;";");" "List". How do I get that to be one string in the end?

     

    I suppose to actually change the source string is not the solution, however is it possible to manipulate the result from ForAll to be one string incorporation the diffrent changes made by substitute?

     

    Confused 🙂

  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @adamtj ,

    Please consider using a collection here - it is so much easier to manipulate the contents.

  • adamtj Profile Picture
    79 on at

    Hi @WarrenBelz ,
    If its easier then im more then willing to try that. However i would appreciate any pointers you could give me on the subject.

     

    My main goal is to change mutliple words in one string dynamically. For example:
    Input: "This is my source string"
    Output: "This **** my **** string"

  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @adamtj ,

    On reading this again, you seem to be replacing a string with itself - what is varGdprLeadsNote.NotesHtmlText and varGdprLeadsNote.GDPRContent - is this a table with two fields and where are you getting the words to replace

  • adamtj Profile Picture
    79 on at

    Hi @WarrenBelz ,

    I will try and explain the whole picture 🙂

    The function for the app is to store and track notes and progress in a new sales leads and its on-boarding process. According to laws in EU (GDPR) information such as e-mail, phone number and similar information that could identify a person is consider sensitive. The law states that this kind of information isn't allowed to store longer than necessary. Hence the information must be traceable and erasable or able to be anonymized.

    So when the user inputs information and notes into the app a series of RegEx searches are made on the text, text that matches "sensitive data" gets marked and the actual words copies and stores in same record as the actual note.

     

    When the user saves the information a record with the notes and marked keywords (matched as sensitive information) will be saved in a table. Both fields are text fields, NotesHtmlText  and GDPRContent 

     

    The record looks like this:

    adamtj_0-1640123710280.png

     

    Now to the tricky part. When the on-boarding are finished or the lead is terminated and appropriate time has past the data should be either anonymized or erased. I'm trying to anonymize the data.

     

    So back to the question:

    varGdprLeadsNote is the selected record in the "LeadNotesTable" that i want to anonymize.

    varGdprLeadsNote.NotesHtmlText is the field that contains the actual note/information submitted by the user. 
    VarGdprLeadsNote.GDPRContent is the field that contains identified sensitive "words", mail phone number etc inside the submitted note/information. The "keywords" are stored as a string separated with ";".

     

    So the thing I'm trying to do is to replace NotesHtmlText with a new string where all of the keywords in GDPRContent  are replaced with "****". 

    However this formula only takes me halfway. The NotesHtmlText remains unchanged which I now understand is expected.

    ForAll(
     //Creates a collection to loop throu with the keywords to anonymize, by parsing the 
     //comma separeted string stored in the 'GDPRContent' field.
     Split(varGdprLeadsNote.GDPRContent;";");
    
     //Replaces the keywords in the submited text.
     Substitute(varGdprLeadsNote.NotesHtmlText; ThisRecord.Result; "****")
    )

     

    If i put the result from the ForAll into a collection I end up with a new collection containing each result from the loop:

    adamtj_1-1640125651008.png

     

    The result i want to write back should look like this:
    <p>Bl bla **** med mer</p><p>Bla **** etc och så vidare</p>

     

    As I said before any input are greatly appreciated!

     

     

  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @adamtj ,

    30 minutes on a model I built and I will have to raise the white flag

    @RandyHayes , you might want to have a look

  • adamtj Profile Picture
    79 on at

    @WarrenBelz, no worries I appreciate your time and effort!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 312

#3
Mohsin Ali Profile Picture

Mohsin Ali 252

Last 30 days Overall leaderboard