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

Extract Initials

Status
Not open for further replies.

gsmithmme

Technical User
Jun 3, 2004
51
0
0
US
I know I am being daft here, but I cannot locate this anywhere. I am using Crystal 8.5 on a Paradox database. I have field that contains either a first name and last name, as well as an "Unknown" (that's the actual text). So examples would be

Greg Smith
Fred Bloggs
Unknown
!Default

I would like to extract the first name letter and the last name letter, so the above would be

GS
FB
UK (that's the tricky one I think)
None selected (if it starts with ! then it's none selected)

Any help would be appreciated. I have been searching through posts and I am surprised I cannot find it.

Thanks.
 
Hi gsmithmme

I am using a later version of CR, but from my (fading) recollwection of 8.5, I think this will still work:

If {table.field} = 'Unknown'
Then 'UK'
Else
If {table.field} [1] <> '!'
Then Split({table.field}, ' ')[1][1] + Split({table.field}, ' ')[2][1]

The data will need to be consistently in the format of 2 names separated ib a single space though. Any variation on that will require a bit of fine tuning.

Hope it helps

Cheers
Pete
 
Awesome! Thanks Pete! .. Now saved in my personal FAQ!
 
Ok. I was nearly there...

Turns out they have some 1 name people in the field. I accounted for the 1 or 2 instances, but in addition to

Fred Bloggs
Greg Smith
Doreen

So... I figured out how you did the 2 names, and I think I can figure it if 3, but what about 1 name?
 
Hi gsmithmme

This should work for you:

If {table.field} = 'Unknown'
Then 'UK'
Else
If Trim({table.field})[1] <> '!'
Then If UBound(Split(Trim({table.field}), ' ')) = 1
Then Trim({table.field})[1]
Else Split(Trim({table.field}), ' ')[1][1] + Split(Trim({table.field}), ' ')[2][1]

I have alos included the Trim function to deal with leading or trailing spaces that are likely to be encountered.

Hope this helps.

Cheers
Pete
 
Helps Immensely Pete! (sorry, out of the country for a couple days!)

Thanks so much!
Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top