[ Strings and Atoms | Reference Manual | Alphabetic Index ]

# string_codes(?String, ?Codes)

Codes is a list whose elements are the character codes of the characters in the string

String
  String or variable.
Codes
  Codes of integer character codes and/or variables, or simply a variable.

## Description

This predicate performs the mapping between a string and the corresponding list of character codes.

If String is instantiated, unifies Codes with the list whose elements are the character codes for the character in the string.

If Codes is instantiated, unifies String with the string composed from the character codes given by the list elements.

### Modes and Determinism

- string_codes(+, -) is det
- string_codes(-, +) is det

### Exceptions

(5) type error
  String is not a string.
(5) type error
  Codes is not a proper list.
(5) type error
  Codes contains non-integer elements.
(6) out of range
  Condes contains integers that are not valid character codes.
(4) instantiation fault
  Both String and Codes are nonground (non-coroutine mode only).

## Examples

       Success:
       string_codes(S,[65,98,99]).          (gives S="Abc").
       string_codes("abc",L).               (gives L=[97,98,99]).
       string_codes("abc",[97,A,99]).       (gives A=98).
       string_codes(S,[127]).               (gives S="\177").
       string_codes("abc",[97|A]).          (gives A=[98,99]).
       Fail:
       string_codes("abc",[98,99,100]).
       Error:
       string_codes(S,[A|[128]]).           (Error 4).
       string_codes(S,[1|A]).               (Error 4).
       string_codes('string',L).            (Error 5).
       string_codes(S,"list").              (Error 5).
       string_codes('string',[128]).        (Error 5).
       string_codes(S,["B"]).               (Error 5).
       string_codes(S,[256]).               (Error 6).

## See Also

string_code / 3, string_chars / 2, string_list / 3, char_code / 2