Jump to content
rob

bold parts of a field

Recommended Posts

So person performs a find for part of the text they wish to find.  The resulting display should bold just the part that they searched for in that field.  I have tried to search for examples but don't even know what to search for.  Hints would be appreciated.  I think I need pattern count but that just gives me a number.

Share this post


Link to post
Share on other sites

You can use a custom function.  Here is one which will work:

/*
boldSelectedText ( text ; search )
purpose:  bolds the search characters within a text string
*/

Let ( [
bolded = TextStyleAdd ( search ; Bold ) ;
len = Length ( search ) ;
pos = Position ( text ; search ; 1 ; 1 )  
] ;
If ( Length ( text ) ;
	If ( pos ; 
		Left ( text ; pos -1 ) & bolded  &
		boldSelectedText ( Right ( text ; Length ( text ) - pos - len  +1 ) ; search ) ;
		text )
	)
)

I've attached a file which shows how it works.  I am sure there are better custom functions.  You would need to capture the search criteria.  You can have the User enter the search string into a global field or enter find mode and then capture that value for your calculation. You could also use a script.  Instead of creating a calculation in your data table, I would use a PLACEHOLDER field.  I've provided a few examples.

PLACEHOLDER fields are great to eliminate calculations used only for display.  Keep in mind that PLACEHOLDERS 1) must remain empty and 2) will not display in preview or print.

BoldSearched.fmp12

  • Like 1

Share this post


Link to post
Share on other sites

There are some nuances worth mentioning here. For example, the default Filemaker find looks for words that begin with the search phrase. Highlighting the search phrase as pattern is more inclusive. Say you searched for "little" and the found record contains "Doctor Doolittle belittled his little friend".  Highlighting the pattern "little" will result in "Doctor Doolittle belittled his little friend" - but the first two highlighted occurrences played no part in the search.

  • Like 2

Share this post


Link to post
Share on other sites

Yep, Laretta, that is what I needed.  Comment thank you also.  Laretta showed that problem in demo file but I use find looking for text anywhere by surrounding with *.  

Share this post


Link to post
Share on other sites

Hi Rob, I suggest that you also check out this custom function which preserves the case (whether capitalized or not) of the search phrase.  In all, it is a better custom function.  Sorry I didn't find this CF before I wrote mine above.

HiliteSingle ( text ; searchString ; color )

Note that you should use the CF Comment has listed further down in the link instead of the original one.  And you'll need to change from highlight to bold but I'm sure you can handle that!  :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Who Viewed the Topic

    1 member has viewed this topic:
    arni 
×

Important Information

By using this site, you agree to our Terms of Use.