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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Last name & first name in a field 1

Status
Not open for further replies.

rmiller11

MIS
Jan 20, 2003
43
US
I want to be able to separate the first, last, and (If exist) middle Initial and (if exist) suffix in a name field that is formatted like this:

"Blow, Jr.~Joseph D"
"Bollinger~Mary D"
"Bird~Jane"

How would I do this? I want to send it to Excel in separate fields with Crystal.

Blow;Jr.;Joseph;D
Bollinger;;Mary;D
Bird;;Jane;
 
rmiller,

Try an approach like this:

//{@Formula1}
WhilePrintingRecords;
StringVar xx := "Blow, Jr.~Joseph D";
StringVar yy;
StringVar Array zz;

//Get rid of the commas and tildas...
yy := Replace(xx,',','');
yy := Replace(yy,'~',' ');
//Cut the string up at the spaces
zz := Split(yy,' ');

Create 4 or 5 formulas like the following and place them side by side;

//{@Formula2}
WhilePrintingRecords;
StringVar Array zz;

If UBound(zz) > 0
Then zz[1];

Create copies of the above formula for as many name components as you wanted to cater for. For each formula, you will have to increment the red numbers by 1. So your second formula uses "> 1" and "zz[2]" etc.

All the best,

Naith
 
Replace "Blow, Jr.~Joseph D" with your literal field name.
 
Can you guess that I haven't tested my own code? [wink]

After this line:

zz := Split(yy,' ');

enter this:
" "

This is because a formula cannot end in an array.

Sorry about all the posts,

Naith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top