Operating System - OpenVMS
1829581 Members
3989 Online
109992 Solutions
New Discussion

extract last name from symbol

 
cylon99
New Member

extract last name from symbol

Hi,

I have a script which requires the input of a users full name as part of account creation process. I now need to modify the script and extract only the last name. This is a bit tricky now as there may be anything up to 6 or so names in the full name depending on the country of origin.

Anyone have any thoughts how I would extract the last name from a symol containing something like DANIEL AUGUSTO GASPAROTTO DOS SANTOS?

Any thoughts would be most welcome?

Thanks,
Daren
3 REPLIES 3
Kris Clippeleyr
Honored Contributor

Re: extract last name from symbol

Daren,
Have a look at the lexical function F$ELEMENT (examples).
Seems like a small loop in DCL will do the trick.
Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Art Wiens
Respected Contributor

Re: extract last name from symbol

If it's your script, the "easier" thing to do would be to modify it to prompt for the individual pieces of the name, First, as many middle names, and then Last name. Other than that if you can be "guaranteed" that there will always be spaces, you can find the last piece using f$element, but what's to say a last name is one "word" ... perhaps Dos Santos is the real family name.

Seperate prompts would make the most sense to me.

Cheers,
Art
Hein van den Heuvel
Honored Contributor

Re: extract last name from symbol

How does the data get into the symbol.
It seems to be kroken already, as it is uppercase only.

Can you influence the data provider to do the right thing and present the lastname as a seperate variable?

In the example posted. What would you want the last name to be? "Santos" or "Dos Santos"? That may be obvious to you, not to me. And I'm serious... what is the actual last name in the example?

My last name is "van den Heuvel", not "HEUVEL".
How can any script automatically determine that?

Are you willing to build in a lot of local-language rules?

Now if you question is not about language and nameing, but just about DCL and grabbing the last word in a piece of string the I would feed it into F$EDIT TRIM+COMPRESS first. Then loop through F$ELEM untill one too far, or look backwards with F$EXTR(end,1,name) untill a space found, then extract forwards.


In PERL:

$ x="DANIEL AUGUSTO GASPAROTTO DOS SANTOS"
$ perl -e "$_ = shift; print $1 if /(\S+)\s*$/" "''x
SANTOS


$_ = shift; # load default variabe $_ from first command argument
print $1 if # print first component remembered in matching expression.

/(\S+)\s*$/ # regular expression.

(\S+) = remember a(any) piece of non-whitepace string
\s* = followed by zero or more spaces
$ = at end or variable.

"''x ! Makes sure data comes in p1 only.


hth,
Hein.