How to extract number

Discussions about CSEntry
Post Reply
khurshid.arshad
Posts: 572
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

How to extract number

Post by khurshid.arshad »

Dear Gregory


"123456789" I want to extract single digit or double digit from any position.


Regards.
Gregory Martin
Posts: 1792
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: How to extract number

Post by Gregory Martin »

If this is a numeric value, you may find it most easy to convert it to a string first. For example, to get the first two digits, you could write:
maketext("%d",xxx)[1:2]
However, that will return it as a string. If you want it as a number again, you can write this:
tonumber(maketext("%d",xxx)[1:2])
If you want digits from the right of the string, you could use the modulo operator. The last two digits are:
xxx % 100
You can use divide and modulo to get middle sections of the string. For example, to get the tens and hundred digits, you would write:
( xxx / 10 ) % 100
khurshid.arshad
Posts: 572
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: How to extract number

Post by khurshid.arshad »

Dear Gregory

Thanks.

arshad
Post Reply