[ ECLiPSe Term Manipulation built-in.|Group Index| Full Index]

char_code(?Char, ?Code)

Succeeds if Code is the numeric character code of the character Char.

?Char
One-character atom, string or variable.
?Code
Integer or variable.

Description

If Char is instantiated to a one-character atom or string, Code is unified with the corresponding numeric character code, depending on the chracter encoding in use.

If Code is instantiated to an integer, Char is unified with the corresponding one-character atom.

Fail Conditions

Fails if Code does not unify with the character code of Char.

Resatisfiable

No.

Exceptions

(5) Type error
Char is instantiated, but not to a 1-character string or atom.
(5) Type error
Code is instantiated, but not to an integer.
(6) Range error
Code is instantiated to an integer outside the valid range for character codes.
(4) Instantiation fault
Neither Char nor Code are instantiated (non-coroutine mode only).

Examples


   Success:
   char_code(b,98).
   char_code("b",98).
   char_code(C,99).     (gives C=c).
   char_code(a,I).      (gives I=97).
   Fail:
   char_code(a,98).
   Error:
   char_code(C,I).       (Error 4).
   char_code(ab,I).      (Error 5).
   char_code(7,I).       (Error 5).
   char_code(C,-1).      (Error 6).


See Also

get_char / 1, get_char / 2, put_char / 1, put_char / 2, string_list / 2, name / 2