Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Name format

Status
Not open for further replies.

pgevaux

Vendor
Mar 4, 2006
14
GB
Just a simple one by I thought I would share it because I couldn't find an answer as simple as this one that I created.

I wanted to change the name format of a string field from 'surname,firstname' to 'firstname surname'

Existing {fullnamestring}:
Smith,John

What I wanted:
John Smith

This is the code to do it:

right ({fullnamestring}, length({fullnamestring}) - instr({fullnamestring}, ","))
& " " &
Left ({fullnamestring}, instr({fullnamestring}, ",")-1)

I hope this helps other novices like me.

Regards
Phil Gevaux
 
Just realised that this formula will fail if there are any NULL values in the field. To get around this use:

stringvar name := trim({fullnamestring});
if length(name) = 0 then " " else
right (name, length(name) - instr(name, ",")) & " " & Left (name, instr(name, ",")-1)
 
A simpler approach is:

Split({fullnamestring},",")[2] + " " + Split({fullnamestring},",")[1]

- Ido

view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Or to add error checking, use:

if ubound(Split({fullnamestring},",")) > 1 then
Split({fullnamestring},",")[2] + " " + Split({fullnamestring},",")[1]
else
{fullnamestring}

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top