## `listlib::sublist` -- search sublists

#### Introduction

`listlib::sublist(`list1, list2`)` determines, whether the list `list1` contains another list `list2`.

#### Call(s)

`listlib::sublist(list1, list2 <, index> <, option>)`

#### Parameters

`list1, list2` | - | MuPAD list
`index` | - | integer, that determines the first search position
`option` | - | option Consecutive

#### Options

`Consecutive` | - | determines that the sublist `list2` is containing coherent in `list1`

#### Returns

the position of the first element of the containing sublist or zero

#### Related Functions

`contains`, `op`

#### Details

- With `listlib::sublist` the position of the first appearance of a list in another list can be determined.
- The position that was found is returned as integer. If the given list does not contain the given `sublist`, the number `0` is returned.
- If an index is given, the search starts at this position. Therewith multiple occurence of a sublist can be determined.
- With the option Consecutive, the list must contain the sublist in one piece without elements in between.

#### Example 1

The sublist is a part of the list, but not in one piece:

    >> listlib::sublist([1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 5, 6])

                                         2

    >> listlib::sublist([1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 5, 6], Consecutive)

                                         0

The list contains the sublist, coherent and incoherent:

    >> listlib::sublist([1, 2, 3, 4, 5, 1, 3, 5], [1, 3, 5])

                                         1

    >> listlib::sublist([1, 2, 3, 4, 5, 1, 3, 5], [1, 3, 5], Consecutive)

                                         6

#### Example 2

Find the last occurence of the sublist inside of the list:

    >> POS:= 0:
       while listlib::sublist([1, 2, 3, 1, 3, 1, 2, 3], [1, 2, 3], POS + 1) > 0 do
         POS:= listlib::sublist([1, 2, 3, 1, 3, 1, 2, 3], [1, 2, 3], POS + 1)
       end_while:
       POS

                                         6

    >> delete POS:

#### Changes

- used to be called `listtools::sublist`

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000