Format names with PROPER

Posted by: Niclas Welander

Format names with PROPER - 09/28/11 02:38 AM


I belive i cant be the first one to ask this question.
I have an issue with firstnames as surenames.
Often people have names lik Ann-Marie.
My customer will format this so both the names stars with a capital letter. Even if the customer writes ann-marie, the print shall be Ann-Marie. I've used the command PROPER, but that does not work. The command thinks the - is a letter...

Can anyone please respond on this to me?

Niclas Welander
Posted by: Sander vd Berg

Re: Format names with PROPER - 09/28/11 03:43 AM

The behavior of PROPER has been improved in PSM 7. The result of PROPER("ann-marie") in PSM 7 will be "Ann-Marie", as expected.

I don't think there is an elegant way to accomplish this in PSM 6. You can try something like this, but it is limited to hyphens and it doesn't take into account that [Field] might contain spaces to begin with:

REPLACE(PROPER(REPLACE([Field], "-", " ")), " ", "-")

If you are familiar with macro's in PSM, perhaps you could use JavaScript instead. The following snippet seems to work okay for simple cases:

function toProperCase(s){
  return s.toLowerCase().replace( /\b((m)(a?c))?(\w)/g,
  function($1, $2, $3, $4, $5) {
    if ($2){
      return $3.toUpperCase() + $4 + $5.toUpperCase();
    return $1.toUpperCase(); 
Posted by: Sander vd Berg

Re: Format names with PROPER - 09/28/11 04:37 PM

It occurred to me that the expression I suggested can be improved like this:

REPLACE(PROPER(REPLACE([Field], "-", " | ")), " | ", "-")

This will turn "ann-marie smith" into "Ann-Marie Smith". It makes the reasonable assumption that [Field] never contains the substring " | ".
Posted by: Niclas Welander

Re: Format names with PROPER - 09/29/11 05:20 AM

Thank's alot, it worked great...