Cspro logic

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
Tsheringcee
Posts: 12
Joined: July 4th, 2017, 4:21 am

Cspro logic

Post by Tsheringcee »

Can you help me if I can select only two digits from a 4 digits number

For example my number is 1152 I want to explain to extract only 51 in a if statement
jfigueroa
Posts: 100
Joined: August 28th, 2014, 12:46 pm

Re: Cspro logic

Post by jfigueroa »

Hi Tsheringcee,

You can try something like:

Code: Select all

string my_string, ls_extract;
numeric my_digit;

my_string = edit("9999",MY_NUMBER);
ls_extract = my_string[3:4];
my_digit = tonumber(ls_extract);
Then you can do whatever you want with the extracted number as numeric on "my_digit" variable, or if you need it as string variable, you can use the "ls_extract" that is already as string.

Hope this could help you.
Regards.
khurshid.arshad
Posts: 572
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Cspro logic

Post by khurshid.arshad »

Dear Tsheringcee;

Please see also this link.

http://www.csprousers.org/forum/viewtop ... umber#p835
a.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Cspro logic

Post by Gregory Martin »

If you go with the suggestion from jfigueroa, here is a comment on the logic. When extracting substrings, the second part after the colon is the number of characters requested, not the ending character. So you would write:
ls_extract = my_string[3:2];
Post Reply