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

Community site session details

Session Id : kV94eL/e9+Fam+tlb8VzLW
Power Apps - Building Power Apps
Answered

HtmlText: Is it possible to use Replace and Substitute functions on a HTML string?

Like (0) ShareShare
ReportReport
Posted on 30 Aug 2023 12:26:39 by 13

Hi guys, hope you're all well!

 

I have a chunk of HTML (with some in-line CSS) within a HtmlText control. I'd like to be able to replace parts of the code on a button click. For example, if I click on a button I'd replace the string 'color:red', with 'color:blue'. 

 

I've tried putting the string into a variable and have tried Replace/Substitute with no luck. 

 

Any guidance would be appreciated, thank you!

  • AndrewR1 Profile Picture
    1,572 Moderator on 30 Aug 2023 at 12:48:50
    Re: HtmlText: Is it possible to use Replace and Substitute functions on a HTML string?

    To achieve dynamic replacement of parts of an HTML string with inline CSS in a HtmlText control, you can follow these steps:

    • Create Variables: Create two variables to hold your HTML content and the modified HTML content:
      ClearCollect(HtmlContent, "<div style='color:red;'>Your content here</div>");
      ClearCollect(ModifiedHtmlContent, HtmlContent);

    Here, HtmlContent holds the original HTML content, and ModifiedHtmlContent will hold the modified HTML.

    • Replace Function: Use the Replace function to replace the desired parts of the HTML string. In this example, replace "color:red;" with "color:blue;":
      OnSelect:
      UpdateContext({
      ModifiedHtmlContent: Replace(HtmlContent, "color:red;", "color:blue;")
      })

    This will update the ModifiedHtmlContent variable with the modified HTML string.

    • Bind HtmlText Control: Bind your HtmlText control to the ModifiedHtmlContent variable:
    • HtmlText.Text = ModifiedHtmlContent

    if this helps can you hit the thumbs up and if it’s resolved your issue set this as the solution 

     

    Many thanks 

    Andrew 

  • Verified answer
    dan-finan Profile Picture
    13 on 30 Aug 2023 at 12:43:13
    Re: HtmlText: Is it possible to use Replace and Substitute functions on a HTML string?

    Sorry guys, I may have jumped the gun on this one. Using a variable to replace the colour name does actually work however it won't display until the entire web page is refreshed. 

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Loading complete