Combining name with spaces

I am currently using @bdbd suggestion. But some of the reasons is I did not give me whole problem just a slice of it. So that solution is more flexible in the ways I need it to be. But some really cool suggestions in this thread I feel like I am just learning more and more.

The TrimAll() shows potential though. I will have to look more into that to see if it would work. Seems very simple and would have the flexibility I need as well.

Thanks @mipiano!

Now (and this is not a joke), if anyone can improve my understanding of the params that TrimAll takes, I'd be grateful. I've never understood...

TrimAll is especially useful for non-roman languages. My sole use case for TrimAll has always been

TrimAll ( "some text " ; 0 ; 0 )

This leaves a single space between each word

3 Likes

I tend to use this:

Let (

name_list =

List (
prefix
; first_name
; middle_name
; last_name
; suffix

)

;

Substitute ( Trim ( name_list ) ; "¶" ; " " )

)

Works well with only subbing in spaces as required, and can also be tweaked to be used for addresses to generate a csv Address format!

3 Likes

Well upon more examination I was getting an extra leading space so I had to add a Trim.

 Trim ( 
       Substitute (
               First & " " 
                   & 
                   Middle & " " 
                   & 
                   Last & " " 
                   & 
                   Suffix & " " 
                   & 
                   Company;
               ["    "; " "];
               ["   "; " "];
               ["  "; " "]
              )
      )

I suggest you trim all your inputs. You otherwise do not control the number of spaces to substitute, therefore can end up with more spaces than the substitution can handle. You also avoid the need to trim your end result.

2 Likes

I'm a bit lazy and can't be doing with all those square brackets, so here's an alternative approach: use a combination of List, Substitute and if necessary LeftWords or TrimAll. For example:

Substitute ( List ( Prefix ; FirstName, LastName ; Suffix ) ; ¶ ; " " )

List will return only items with values with no last return. If you don't have an auto-enter to get rid of spaces in the fields, you can use LeftWords ( field ; 5 ) or TrimAll for each of the list items.

But hey, each to their own. All are as valid as each other if they work.