Kbase P123744: 4GL/ABL: How to get the ASCII value of an ASCII character?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/02/2009 |
|
Status: Verified
GOAL:
4GL/ABL: How to get the ASCII value of an ASCII character?
GOAL:
How to get the ASCII character of an integer value?
GOAL:
What is the inverse function of the CHR function?
GOAL:
What is the inverse function of the ASC function?
GOAL:
How to reverse the CHR function?
GOAL:
How to reverse the ASC function?
FACT(s) (Environment):
All Supported Operating Systems
Progress 8.x
Progress 9.x
OpenEdge 10.x
FIX:
Use the ASC function to obtain the ASCII (or internal code page) integer value of a single character. For example, in the following code, the ASC function returns the value of 65:
The following example is using ASCII character set and not using Unicode (UTF) code page.
DEFINE VARIABLE iAsciiValue AS INTEGER NO-UNDO.
ASSIGN
iAsciiValue = ASC("A").
MESSAGE iAsciiValue
VIEW-AS ALERT-BOX INFO BUTTONS OK.
Use the CHR function to obtain the single ASCII (or internal code page) character of its integer input parameter. For example, in the following code, the CHR function returns the single ASCII character "A":
DEFINE VARIABLE cAsciiCharacter AS CHARACTER NO-UNDO.
ASSIGN
cAsciiCharacter = CHR(65).
MESSAGE cAsciiCharacter
VIEW-AS ALERT-BOX INFO BUTTONS OK.
The ASC and CHR functions are inverses of each other. Thus, CHR(ASC(cAsciiCharacter)) = cAsciiCharacter and ASC(CHR(iAsciiValue)) = iAsciiValue as demonstrated in the following code:
DEFINE VARIABLE cAsciiCharacter AS CHARACTER NO-UNDO.
DEFINE VARIABLE iAsciiValue AS INTEGER NO-UNDO.
ASSIGN
iAsciiValue = 65
cAsciiCharacter = "A".
MESSAGE
CHR(ASC(cAsciiCharacter)) = cAsciiCharacter "~n"
ASC(CHR(iAsciiValue)) = iAsciiValue
VIEW-AS ALERT-BOX INFO BUTTONS OK.