substring(+string, +integer_start, +integer_num)

This string predicate is used for copying a part of a string into another string. The first argument is the string to copy from. The second argument is an integer that determines from which character the copying starts, the index of the first character in a string is 1. The third argument is the number of characters to copy. The predicate fails if the copying continues past the end of the string.

see also: &/2 delete/3 expand_sq/1 insert/3 is/2 replace/3 string_list/2 to_lower/1 to_prolog/1 to_string/1 to_string/2 to_upper/1  trim/1 triml/1 trimr/1 working with strings

Examples
X is_string substring("computers", 4-1*2, 3+3). X="ompute"
X is_string substring("computers", 1, 2). X = "co"
X is_string substring(computers, 1, 2). X = co
X is_string substring(computers, 1, 12). fails

 

Exceptions
the argument Arg is a variable an instantiation_error exception is thrown
the first argument is a floating point number a type_error(evaluable, PredInd) exception is thrown, PredInd is the predicate indicator of the term that cannot be evaluated
the second and/or third argument is not evaluable as an integer expression a type_error(evaluable, PredInd) exception is thrown, PredInd is the predicate indicator of the term that cannot be evaluated
the second argument Arg is smaller than 1 an evaluation_error(not_positive, Arg) exception is thrown
thid argument Arg is a negative value an evaluation_error(not_pos, Arg) exception is thrown

 

 

info@trinc-prolog.com