Page 1 of 1

How to get the ascii code for the first character in a strin

Posted: Mon Mar 13, 2006 3:20 am
by LANDO
Hello,

I need to check if a column data is numeric or character.
the data I get can only come in 2 ways for that column number or varchar2 ( the datatype of the column is ofcourse varchar2 )
I thought I'll just check for the ascii range of the first character ( If it is not between Ascii(48) and Ascii(57)) then it is a character
Anyway that is what I'm trying to do but, I just can't find a way to simply get the ascii code for the first character.

Any suggestions or clarifications will be appreciated.

Posted: Mon Mar 13, 2006 3:31 am
by ameyvaidya
Hi Lando,
Check out the NUM() Function in the BASIC guide(Pg 509), It does exactly what you need done.

If you want to check only the first character of the incoming string, the expression:

Code: Select all

SEQ(<in.col>[1,1])
will give you the ASCII code of the first character (Watch out for leading spaces if any with this approach).

IHTH

Posted: Mon Mar 13, 2006 6:07 am
by ray.wurlod
Alpha(Left(InLink.TheString,1)) will return 1 if the first character is alphabetic, or 0 otherwise. Num(Left(InLink.TheString,1)) will return 1 if the first character is numeric or 0 otherwise. You can combine the logic with the Boolean operator Or to get the test expression you seek.

Code: Select all

Alpha(Left(InLink.TheString,1)) Or Num(Left(InLink.TheString,1)) 

Posted: Mon Mar 13, 2006 6:13 am
by LANDO
Thank you both for your replies.
Both replies are good enough for me !
:D