String comparisons - compare match first last wordend

Table of Contents

String comparisons - compare match first last wordend
Example

String comparisons - compare match first last wordend

There are 6 string subcommands that do pattern and string matching. These are relatively fast operations, certainly faster than regular expressions, albeit less powerful.

string compare string1 string2

Compares string1 to string2 and returns:

  • -1 ..... If

    string1 is less than

    string2

  • 0 ........ If

    string1 is equal to

    string2

  • 1 ........ If

    string1 is greater than

    string2

These comparisons are done alphabetically, not numerically - in other words "a" is less than "b", and "10" is less than "2".

string first string1 string2

Returns the index of the character in

string1 that starts the first match to

string2, or -1 if there is no match.

string last string1 string2

Returns the index of the character in

string1 that starts the last match to

string2, or -1 if there is no match.

string wordend string index

Returns the index of the character just after the last one in the word which contains the

index'th character of

string. A word is any contiguous set of letters, numbers or underscore characters, or a single other character.

string wordstart string index

Returns the index of the character just before the first one in the word which contains the

index'th character of

string. A word is any contiguous set of letters, numbers or underscore characters, or a single other character.

string match pattern string

Returns 1 if the

pattern matches

string. The

pattern is a