IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#37356 - 09/28/11 02:38 AM Format names with PROPER
Niclas Welander Offline
OL Newbie

Registered: 11/03/09
Posts: 18
Loc: Sweden
Hi!

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?

Greatings
Niclas Welander
Sweden

Top
#37357 - 09/28/11 03:43 AM Re: Format names with PROPER [Re: Niclas Welander]
Sander vd Berg Offline
OL Expert

Registered: 06/10/08
Posts: 207
Loc: Objectif Lune NL
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:

Code:
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:

Code:
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(); 
  });
}

Top
#37368 - 09/28/11 04:37 PM Re: Format names with PROPER [Re: Sander vd Berg]
Sander vd Berg Offline
OL Expert

Registered: 06/10/08
Posts: 207
Loc: Objectif Lune NL
It occurred to me that the expression I suggested can be improved like this:

Code:
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 " | ".

Top
#37374 - 09/29/11 05:20 AM Re: Format names with PROPER [Re: Sander vd Berg]
Niclas Welander Offline
OL Newbie

Registered: 11/03/09
Posts: 18
Loc: Sweden
Thank's alot, it worked great...

:-)

Top