[ Strings and Atoms | Reference Manual | Alphabetic Index ]
string_code(+Index, +String, -Code)
Succeeds if Code is the value of the Index'th byte in String
- Index
- Integer between 1 and the length of String
- String
- String
- Code
- Variable or Integer
Description
This predicate extracts the Index'th byte from the given string String.
Bytes 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.
For backward compatibility with earlier versions of ECLiPSe, the
argument order string_code(String,Index,Code) is also allowed.
Modes and Determinism
- 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
string_code(1, "abc", 97). % succeeds
string_code(3, "abc", C). % gives C = 99
string_code(2, "abc", 100). % fails
string_code(_, "abc", C). % Error 4
string_code(1, _, C). % Error 4
string_code(1.5, "abc", C). % Error 5
string_code(1, abc, C). % Error 5
string_code(0, "abc", C). % Error 6
string_code(4, "abc", C). % Error 6
See Also
string_list / 2, char_code / 2