Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Panel
Table of Contents

Anchor
1154955
1154955
Syntax

findstring seq=sequence [pos=index] [case=yes|no] [num=number|last]

Anchor
1154958
1154958
Description

Anchor
1154959
1154959
The find command finds a specific occurrence of a substring in an existing string or list element.

Anchor
1154960
1154960
The first parameter, string, is the string in which to search for the sequence. It can be a variable reference or a literal. The seq parameter specifies the sequence for which the search is being made.

Anchor
1154961
1154961
The optional pos parameter specifies the one-based index of the string where the find operation begins.

Anchor
1154962
1154962
The optional case parameter indicates whether the search is case-sensitive (yes) or case-insensitive (no). Default = no.

Anchor
1154963
1154963
The optional num parameter specifies the instance of the sequence for which the search is being made. If the value of num is last, the find function gives back the index of the last occurrence of the sequence in the string.

Anchor
1154964
1154964
If the sequence is found, the index (one-based) of the starting point of the requested occurrence is place in the _lastrc.result variable. If the sequence was not found in the string, a value of -1 is placed in the _lastrc.result variable.

Anchor
1154965
1154965
If the sequence is found, _lastrc.message contains a value of MATCH. If the sequence could not be found, _lastrc.message contains NO_MATCH.

Anchor
1154966
1154966
Parameters

Anchor
1154994
1154994

Parameter

Description

string

String in which to search for the sequence.

seq=sequence

Sequence for which the search is being made.

pos=index

One-based index of the string where the find operation begins.

case=yes | no

Specification of whether the search is case-sensitive (yes) or case-insensitive (no).

Default is no.

num=number | last

Instance of the sequence for which the search is being made.

Anchor
1154996
1154996
Examples


Anchor
1154997
1154997
The following examples demonstrate the find command:

Panel


find "This is a test" seq=is
echo $(_lastrc.result)
3

find "This is a test" seq=" " num=2
echo $(_lastrc.result)
8

set mystring="I love examples"
find "$(mystring)" seq=EXAMPLES case=yes
echo $(_lastrc.result)
-1

find "This is a test" seq=" " pos=6
echo $(_lastrc.result)
8


Anchor
1154931
1154931

Anchor
1154381
1154381