Re: 4GL questions
Posted in 1993
->}gau@mendel.sing.ingr.com (Gau Lai Choon) asks: ->} ->} Question 1 ->} ---------- ->} Is there a built-in function to convert an alphabet to it's ascii ->} representation and vice visa. (eq. /065 to-from 'A') ->johnl@informix.com (Jonathan Leffler) answers: -> -> LET x = ASCII(34) -> but not vice versa alan@den.mmc.com (Alan Popiel) adds: The syntax `LET x = ASCII 34' also works. The following function, does the other conversion: /* Created by: Alan Popiel, 10/27/93 * * ord() returns the numeric value of the ASCII code for the first character * of the string passed to it from an Informix 4GL routine. * * syntax: * CALL ord(str) RETURNING number * LET number = ord(str) * * CALL argument: * str -- 4GL character string, normally of length 1. If length is greater * than 1, the the code for the first character is returned. * * RETURNING argument: * integer number -- numeric value of the ASCII code; * Note: negative values are returned for ASCII codes > 127. To fix this: * IF number < 0 THEN * LET number = number + 256 * END IF */ int ord(nargs) int nargs; { char str[512]; /* Input from stack: Allow for long strings. */ /* Pop calling argument from the stack. */ popquote(str,sizeof(str)); /* Push return arguments to the stack. */ retint((unsigned)str[0]); /* ASCII code of first character. */ return(1); /* Number of arguments pushed. */ } Regards, Alan ___________________________ ______________________| R. Alan Popiel |__________________________ \\ Internet: | Martin Marietta, Tech Ops | / \\ alan@den.mmc.com | P.O. Box 179, M/S 5422 | Std disclaimers apply. / )Voice: | Denver, CO 80201-0179 USA | ( / 303-977-9998 |___________________________| (But you knew that!) \\ /________________________) (____________________________\\