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

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
LANDO
Participant
Posts: 16
Joined: Mon Jan 09, 2006 3:35 am

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

Post 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.
Best Regards,
Lando
ameyvaidya
Charter Member
Charter Member
Posts: 166
Joined: Wed Mar 16, 2005 6:52 am
Location: Mumbai, India

Post 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
Amey Vaidya<i>
I am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand.</i>
<i>- Douglas Adams</i>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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)) 
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
LANDO
Participant
Posts: 16
Joined: Mon Jan 09, 2006 3:35 am

Post by LANDO »

Thank you both for your replies.
Both replies are good enough for me !
:D
Best Regards,
Lando
Post Reply