Page 1 of 1

Character to Number

Posted: Mon Mar 14, 2011 12:45 pm
by rsunny
Hi ,

Can any one tell me how to convert Character to Decimal Value . For example if i have A , it should convert to 65 . and if i have Aa it should convert to 6597.

Any help is really appreciated

Thanks in advance

Posted: Mon Mar 14, 2011 12:54 pm
by leomauer
Use Seq function for each character in string:
Seq(<strig>[1,1]):Seq(<strig>[2,1]):Seq(<strig>[3,1]) and so on.

Posted: Mon Mar 14, 2011 1:02 pm
by rsunny
leomauer wrote:Use Seq function for each character in string:
Seq(<strig>[1,1]):Seq(<strig>[2,1]):Seq(<strig>[3,1]) and so on.
Hi ,

Thanks for your quick reply , but the logic above is for each character and i want for multiple characters. I mean , i dont know the input , the input might be abc for 1 row and sdfge for 2nd , so if that is the case how do i consider . So if i consider the above logic that u said ,after all the characters are converted to decimal do i need to trim all zeroes since "" is converted to zero r8?


thanks in advance

Posted: Mon Mar 14, 2011 1:08 pm
by DSguru2B
Right a small routine to cycle through the string and return the decimal value all concatenated.

Posted: Mon Mar 14, 2011 1:09 pm
by leomauer
I see you are using DataStage Server edition. Then write BASIC routine looping thriugh the string character by character and concatenating the results until you reach the end of the string.
As for trimming zeroes. in the string absence of character is not converted to anything.

Posted: Mon Mar 14, 2011 1:21 pm
by rsunny
Hi ,

Thanks all for the reply . As i dont have any experience in writing Routines , Can anyone guide me how to write a routine to solve this issue.

Any help is really appreciated

Thanks in advance

Posted: Mon Mar 14, 2011 1:29 pm
by ray.wurlod
You've been using DataStage for quite a while now (based on your DSXchange profile) and really should be acquiring these skills.

Code: Select all

FUNCTION RSunny(aTheString)

    vLenString = Len(aTheString)
    Ans = ""

    For vChPos = 1 To vLenString
        Ans := Seq(aTheString[vChPos,1])
    Next vChPos

RETURN(Ans)
If you have Unicode data, then use Uniseq() rather than Seq() function.