Page 1 of 1

Cspro logic

Posted: July 4th, 2017, 7:14 am
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

Re: Cspro logic

Posted: July 4th, 2017, 10:46 am
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.

Re: Cspro logic

Posted: July 4th, 2017, 10:48 am
by khurshid.arshad
Dear Tsheringcee;

Please see also this link.

http://www.csprousers.org/forum/viewtop ... umber#p835
a.

Re: Cspro logic

Posted: July 4th, 2017, 11:18 am
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];