Do you have filemaker advanced so that you can set up a custom function for this. Custom functions can be set up as recursive functions and this will enable the loop you want.
Yes I have advanced.
How do I go about the recursive function?
To rebuild the the string I am assuming I have to set a new variable $NewString then $NewString = $NewString & " " & $Word which will add a leading space at the begining of the string, then Trim ( $NewString).
A recursive function is a function that calls itself, passing a simpler version of the original data so that eventually a value is returned which then chains back through the previous calls until a result for the original data is produced. It has a smoke and mirrors look to many, but it works.
Let's call your function SmartCapital with a single parameter: txtWords.
Let ( Word = LeftWords ( txtText ; 1 ) ;
Case ( WordCount ( txtWords ) < 1 ; Upper ( Left ( Word ; 1 ) ) & Right ( Word ; Length ( Word ) - 1 ) ;
Upper ( Left ( Word ; 1 ) ) & Right ( Word ; Length ( Word ) - 1 ) & " " & SmartCapital ( RightWords ( txtWords ; WordCount ( txtWords ) - 1 ) )
) /* end case */
) /* end let */
You'd use this in an expression such as SmartCapital ( FieldName ) to capitalize the contents of field name. You can also use it in an auto-enter calculation such as SmartCapital ( self ) to auto capitalize text after it has been entered in a text field.
The function capitalizes the last word first, then the next to last, and so forth until a capitalized string of all the words are returned by the original call to the function.
Note: custom functions work best in unstored calculations or auto-enter calculations. They can be made to work with stored calculations, but be aware of the following issue while developing and testing a new custom function:
So the variable 'word' is created locally to each function call. So if there are five words inthe string, five seperate 'word' variables are created local to each call of the function. The function is called five times until there is one word (WordCount( txtWords) <= 1)which is then capitalised, and concatonated to the previous words, then that function ends. Then remainder of the code in the previously called function is executed, capitalises that word then concatonated to the previous words, the function exited and so on untill all five words are capitalised then the original function exited with all words capitalised.
I takes a little to get your head around but does make sense. I hope my understanding is correct?
Again many thanks. Your help is always appreciated.
Exactly, that's how "end point recursion--which is what this is called in the computer programming textbooks--works. And this is why I said it looks a bit like "smoke and mirrors" to many. ;-)