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 : rYLLQFfn/YmDr3ywFgdbpY
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!

I have the same question (0)
  • 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. 

  • 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 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 714 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 419 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 243

Last 30 days Overall leaderboard
Loading started
Loading complete