sub_string
Entity: predicate

Usage:
sub_string( Sub, String, Start, Length )

Returns in Sub the substring of String that starts from position Start and has length Length . The variable String has to be instantiated with a string, Other variables can be not-instantiated.

By putting data in some of the variables Sub , Start and Length and leaving the others not-instantiated, you can use the predicate sub_string in six various ways:

1. If all variables are instantiated then it checks if the string Sub is substring of String which starts from Start and having length Length . If in this case Length is not instantiated then it receives the length of Sub .

2. If only Sub is instantiated then predicate works as Find . It search for occurrence of Sub in String . Once found, it returns its start position in Start . By backtracking this predicate returns all such start positions (the Sub can occur several times in String ). In Length this predicate returns the length of Sub . If Length is instantiated then checks if the length of Sub is equal to Length .

3. If only Sub is not instantiated then instantiates it with the substring of String which starts from Start and having length Length .

4. If Sub , Start and Length are not-instantiated then returns in them a substring with its start position and length. By backtracking this predicate returns all substrings of String with their start positions and lengths (look at the example).

5. If Sub and Start are not-instantiated, but Length is instantiated then returns in Sub and Start a substring with its start position which has length Length . By backtracking this predicate returns all substrings of String which have length Length .

6. If Sub and Length are not-instantiated, but Start is instantiated then returns in Sub and Length a substring with its length which has start position Start . By backtracking this predicate returns all substrings of String which have start position Start .

Example:

?- sub_string(Sub, "Sub String", Start, Length), write([Sub, Start, Length]), nl, fail.