I am building a find and replace tool for a canvas app. The text is HTML.
When I use Substitute using in or exactin, it subs partial match in addition to the whole word I am replacing.
'string' will sub all occurrences of 'string' in the HTMLtext, including the word 'strings'
The result is that any formatting used as the sub will be applied to the partial match. I am thinking of using a len() for Boolean comparison but would like to ask for recommendations.
If( Substitute(First( Split( Last( Split( richtextFind.HtmlText, "<p>" ) ).Result, "</p>" ) ).Result," "," ") in varE, Set(varE, Substitute(varE, Substitute(First( Split( Last( Split( richtextFind.HtmlText, "<p>" ) ).Result, "</p>" ) ).Result," "," "), First(Split(Last(Split(richtextReplace.HtmlText,"<p>")).Result,"</p>")).Result) ) )
You did hit my radar with this one! I needed to pull up some apps that I have where I've done this properly.
The problem in your formula is that you are trying to do this in a "program like" way. The substitute function is not decerning, so it will just replace any occurrence that it sees.
What you really need to do is find the place that the occurrence starts and, in your case, base that on a word boundary. Then rebuild the string - left up to the occurrence, then the replacement, then right from the occurrence plus length to the end.
The above is the basics. I found where I use this concept in the past, and I have it as a component that does multiple find and replace in text. So, it is a little more complex for what you appear to be doing - which is to just find and replace a single text.
I am not following your requirements based on your formula completely, it almost appears that you are just trying to substitute with   so I am not sure where you are referencing "string" as your post describes.
Yea the sub for   with   resolved the finding the string from the RichTextEditor that contains spaces in the variable text string. I can share a clip of how this is currently working.
So what is your ultimate goal on the formula? Are you trying to substitute just one or multiple words in the html text?
I am thinking of the same approach. Will update when I solve.
Goal is to sub one word or phrase at a time, formatting inclusive. I saw the cannon you built back in December for the multi-word replacement. Very nice BTW! I'm okay with making the small changes via a feature like this. Manually editing the Rich Text was taking too long.
Since I am trying to be rigid on what I am finding, the sub   with   catches blank spaces unintentionally formatted with the word preceding it. Sometimes the bold and italic tags will wrap the space as well.. see
Yes, the multi-word replacement back in December is a good reference. I eventually took that concept and put it into a component that I reuse for find/replace and also for highlighting words.
I would start with the post from Dec and see where that takes you.
Just let me know if you get stuck!
Keep up to date with current events and community announcements in the Power Apps community.
A great place where you can stay up to date with community calls and interact with the speakers.
Check out the latest Community Blog from the community!