Highlighted Find & Replace

One of the most powerful features of any and all software is the ability to search and identify things which would be human impossible without computers. The ability to search for any given string and have that combination of characters be instantly presented is what has made our current world possible.

In this video, we take a look at FileMaker's default Find & Replace feature and we integrate this into our database systems. We then enhance that feature by implementing a Highlighting feature based on what the user is searching for.

With both the Find & Replace feature and the ability to highlight all occurrences, we have a pretty powerful solution for users who need to be able to modify and make changes to data based on what they're searching for.

AttachmentSize
Highlighted_Find_Replace.zip1.59 MB

Comments

Matt, I do believe you've forgotten about the Exact() function.

I added a global number field, MATCH_CASE_BOOL, to your table and modified the auto-enter calc on the HIGHLIGHTED field to the following (I have the modified file zipped and ready, I'll email it to you):

Let ( [
~match = SEARCH;
~content = CONTENT;
~matchField = GetFieldName ( SEARCH );
~contentField = GetFieldName ( CONTENT );
~exactMatch = MATCH_CASE_BOOL ; // True if matching case required
~styles = HighlightYellow + Bold;
~count = PatternCount ( ~content ; ~match );
~calc = CustomList ( 1 ; ~count ;
"Let ( [ ~search = " & ~matchField & ";"
& " ~text = \"" & ~contentField & "\";"
& " ~start = Position ( " & ~contentField & " ; " & ~matchField & " ; 1 ; [n] ) ; "
& " ~found = Middle ( " & ~contentField & " ; ~start ; " & Length ( ~match ) & " ) ; "
& " ~exactMatch = " & ~exactMatch & " ; "
& " ~highlight = Exact ( ~search ; ~found ) ; "
& " ~function = \"Replace ( $variable ; \" & ~start & \" ; " & Length ( ~match ) & " ; TextStyleAdd ( \" & Quote ( ~found ) & \" ; " & ~styles & " ) ) \" ; "
& " ~useFunction = If ( ~exactMatch ; If ( ~highlight ; ~function ; \"\" ) ; ~function ) "
& "] ; "
& "~useFunction"
& ")"
)
];
If ( IsEmpty ( ~match ) or not ~count ; TextFormatRemove ( ~content ) ;
Evaluate (
List (
"Let ( [";
"$variable = TextFormatRemove (" & ~contentField & ");";
"$variable = " & Substitute ( ~calc ; "¶" ; ";¶$variable = " );
"]; $variable )";
)
)
)
)

/*

FileMaker 18+ can use the While function, but the CustomList works with versions going WAY BACK.

While (
[
~match = SEARCH;
~content = CONTENT;
~contentField = GetFieldName ( CONTENT );
~matchExact = MATCH_CASE_BOOL ; // True if matching case is required
~styles = HighlightYellow + Bold;
~count = PatternCount ( ~content ; ~match );
~i = 0;
~result = ""
];
~i < ~count;
[
~i = ~i + 1;
~position = Position ( ~content ; ~match ; 1 ; ~i );
~length = Length ( ~match );
~found = Middle ( ~content ; ~position ; ~length ) ;
~highlight = Exact ( ~match ; ~found ) ;
~calc = "Replace ( $variable ; " & ~position & " ; " & ~length & " ; TextStyleAdd ( Middle ( " & ~contentField & " ; " & ~position & " ; " & ~length & " ) ; " & ~styles & " ) )";
~result = List ( ~result ; If ( ~matchExact ; If ( ~highlight ; ~calc ; "" ) ; ~calc ) )
];

If ( IsEmpty ( ~match ) or not ~count ; TextFormatRemove ( ~content ) ;
Evaluate (
List (
"Let ( [";
"$variable = " & ~contentField & ";";
"$variable = " & Substitute ( ~result ; "¶" ; ";¶$variable = " );
"]; $variable )";
)
)
)

)

*/

--
Daniel Farnan

Ignorance is curable, not preventable