1828038 Members
1968 Online
109973 Solutions
New Discussion

Use which lexical?

 
SOLVED
Go to solution
Davor_7
Regular Advisor

Use which lexical?

now, i can assign a symbol as below:
$ sh sym syma
SYMA = " keyword: 57"

i want the number "57"(this length will be changed, sometimes 57(2-bits), or 102(3-bit))
but i can not think out a way to get it through f$element or f$extract...
do you have any idea ?
8 REPLIES 8
Ian Miller.
Honored Contributor
Solution

Re: Use which lexical?

This gets the value of the number
x=F$NUMBER(f$element(1,":",syma))

____________________
Purely Personal Opinion
John Abbott_2
Esteemed Contributor

Re: Use which lexical?

I think Ian means F$INTEGER & not F$NUMBER.
Don't do what Donny Dont does
Kris Clippeleyr
Honored Contributor

Re: Use which lexical?

Hi,

Assuming the symbol definition only varies after the colon (:),
you have two (2) possibilities:
1. x = f$integer(f$element(1,":",syma))
2. x = f$integer(f$extract(10,f$length(syma),syma))

Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Jan van den Ende
Honored Contributor

Re: Use which lexical?

Davor,

well, use Ian's answer, but F$NUMBER should be replaced by F$INTEGER.

-- and most of the time, you do not need the explicit F$INTEGER at all.
If you need the number without leading zeroes, just use the symbol name. If used in numeric calculations, the value is automagically converted.

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Ian Miller.
Honored Contributor

Re: Use which lexical?

yes

x=F$integer(f$element(1,":",syma))

It should be - this is what you get from not copying directly from the terminal window :-)

____________________
Purely Personal Opinion
Hein van den Heuvel
Honored Contributor

Re: Use which lexical?


F$ELEM is the way to go normally.

There is one more technique that is often overlooked (unknown) which can give you the answer quickly: String subtraction!

If you know the exact string for " keyword", let's say "TEST", then the solution can be:

$ syma = " TEST:57"
$ number = syma - " TEST:"
$ show symb number
NUMBER = "57"
$ write sys$output f$type(number)
INTEGER
$ other_number = syma - "TEST" - ":"
$ show symb other_number
OTHER_NUMBER = " 57"
$ write sys$output f$type(other_number)
INTEGER
$

Note also how you do not need to strips spaces or do an explicit integer convert.

fwiw,

Hein.



Davor_7
Regular Advisor

Re: Use which lexical?

thanks all
i think the lexical function is very great :)
Davor_7
Regular Advisor

Re: Use which lexical?

close it :p