cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
msong
Level: Power Up

Change word color in string if word is in Table

Hi,

 

I am trying to format words within a string depending on if that word exists in a table column. For example, if I have the following in an HtmlText:

Hello world, my name is X

And I have the single-column table:

Result
---------
Bob
Drew
X
name

How can I get my string to show up as:

"Hello world, my name is X"

 

I've tried doing something with Substitute() and Filter(), but I have not been able to achieve anything. Any help is appreciated

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Change word color in string if word is in Table

Hi @msong 

 

If your string could be of any length, you can create a collection with all the words and later perform a concatenation to show the result in desired format:
 
Expression:
ForAll(Split(testvar," "),If(Result in NamesList,Collect(test123,"<font color=Red>"&Result&"</font>"),Collect(test123,Result)))
 
Here, test123 is the name of my local collection, and to use this on the HTML text you can try out below expression:
Expression: Concat(test123,Value," ")sd.png

 

Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
4 REPLIES 4
Super User
Super User

Re: Change word color in string if word is in Table

Hi @msong 

 

Can you try out the below expression:
"Hello world, my <font color="&If("X" in NamesList,"Red","Black")&">name</font> is <font color="&If("X" in NamesList,"Red","Black")&">X</font>"
Here, NamesList is the name of one column table that I have used in my scenario. Please replace this with the actual value.cc.png

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

msong
Level: Power Up

Re: Change word color in string if word is in Table

@yashag2255 

 

That would work, except the string is dependent on a variable. If I had a variable sentence, I would not be able to hard code the font colors in html as every word in sentence would be constantly changing. I hope that makes sense.

 

Is there a way to possibly loop through all the words in the string using ForAll() or something similar?

 

Thanks!

Super User
Super User

Re: Change word color in string if word is in Table

Hi @msong 

 

If your string could be of any length, you can create a collection with all the words and later perform a concatenation to show the result in desired format:
 
Expression:
ForAll(Split(testvar," "),If(Result in NamesList,Collect(test123,"<font color=Red>"&Result&"</font>"),Collect(test123,Result)))
 
Here, test123 is the name of my local collection, and to use this on the HTML text you can try out below expression:
Expression: Concat(test123,Value," ")sd.png

 

Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
msong
Level: Power Up

Re: Change word color in string if word is in Table

@yashag2255 It Worked! Thank you so much! 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 115 members 4,846 guests
Please welcome our newest community members: