[ Strings and Atoms | Reference Manual | Alphabetic Index ]

# get_string_code(+Index, +String, -Code)

Succeeds if Code is the value of the Index'th character code in String

Index
  Integer between 1 and the length of String
String
  String
Code
  Variable or Integer

## Description

This predicate extracts the Index'th character code from the given string String. Character codes in the string are numbered from 1 (analogous to array indices in subscript/3 and arg/3).

Note that (like all predicates that return a number as their last argument), this predicate can be used as a function inside arithmetic expressions.

### Modes and Determinism

- get_string_code(+, +, -) is det

### Exceptions

(5) type error
  Index is not an integer
(5) type error
  String is not a string
(5) type error
  Code is instantiated but not to an integer
(6) out of range
  Index is an integer less than 1 or greater than String's length
(4) instantiation fault
  Either Index or String are uninstantated

## Examples

       get_string_code(1, "abc", 97).     % succeeds
       get_string_code(3, "abc", C).      % gives C = 99

       get_string_code(2, "abc", 100).    % fails

       get_string_code(_, "abc", C).      % Error 4
       get_string_code(1, _, C).          % Error 4
       get_string_code(1.5, "abc", C).    % Error 5
       get_string_code(1, abc, C).        % Error 5
       get_string_code(0, "abc", C).      % Error 6
       get_string_code(4, "abc", C).      % Error 6

## See Also

string_code / 3, string_codes / 2, string_list / 2, char_code / 2