I have calculation fields that combine peoples names. I have first, last, middle, suffix, and company. I have been making evolving calculations to combine them and it seems every evolution brings up another issue. I either add a space where I do not want one or not add a space at all.
Below is the current attempt and this is not taking into account that there might not be a middle name and hence dose not add a space between first and last name. I am sure if I keep evolving this code I will figure out something that will work but I figured it would be smarter to ask for help as I am sure someone has solved this issue already.
Let
(
[
First = Trim ( Parcel Info | Current Owner | First Name 1 )
; Middle = Trim ( Parcel Info | Current Owner | Middle Initial 1 )
; Last = Trim ( Parcel Info | Current Owner | Last Name 1 )
; Suffix = Trim ( Parcel Info | Current Owner | Suffix 1 )
; Company = Trim ( Parcel Info | Current Owner | Company )
] ;
Case ( not IsEmpty ( Last ) ;
Last
)
&
Case ( not IsEmpty ( Middle) ;
Case ( not IsEmpty ( Last ) ;
" " & Middle;
Middle
)
)
&
Case ( not IsEmpty ( First) ;
Case ( not IsEmpty ( Middle) ;
" " & First;
First
)
)
&
Case ( not IsEmpty ( Suffix ) ;
Case ( not IsEmpty ( First) ;
" " & Suffix ;
Suffix
)
)
&
Case ( not IsEmpty ( Company ) ;
Case ( not IsEmpty ( Suffix ) ;
" " & Company ;
Company
)
)
)
Using the calculation above this ends up not adding a space between first and last name so it ends up being HenryRobinson. I would like it to be Henry Robinson. But in my experience people seem to enter all kinda of odd combination of names. They might enter middle and last but for some odd reason skip the first name. I need a calculation to account for all possible ways a user could enter the name.
Man it is amazing how many options one has when building code. Some times the solution is so simple you just do not see it. Thanks for much for this it worked perfect. Well almost I had to add a space to the last substitute to 2 spaces instead of one.
I am also most sad though as I was about to try my first While in a calculation. I am sure I will have another chance soon though.
Hi @Malcolm , went through all those workarounds with case and replaces too before I came to this.
The ignoring of empty values of the list function can be very handy, although can be a pitfall too
No, that would in my opinion not be a problem. Only the double spaces if a field is empty. You only have to take a value for the count of words higher than the max number of concatenated words.
Interesting idea. I think I will need to try it to learn more. Not sure I have used LeftWords(). Would this take into account more than 2 spaces? Or better yet any multiple of spaces?
If I needed to reduce arbitrary quantities of space chars, I'd reach for something trickier, but I'd still probably keep it within the FMP calc engine functions.
Also:
I've seen the use of the TrimAll function to address this type of scenario, but I don't tend to use it, just because I've never completely understood what the docs are trying to tell me for that function.