# &sin(4)

[Home] [Commands] [Variables] [Macro-Dev] [Glossary]

## NAME

&sin, &isin, &rsin, &risin - String in string test functions

## SYNOPSIS

&sin str1 str2
&isin str1 str2
&rsin str1 str2
&risin str1 str2

## DESCRIPTION

These functions test for the existence of str1 in str2, returning the position of the string in str2 or 0 if not found.

The functions may all be abbreviated to their three letter abbreviation (i.e. &risin may be expressed as &ris). In all cases the first argument is completely evaluated before the second argument.

&sin str1 str2

Returns `0` if string str1 does not exists in string str2. Otherwise the function returns the character position + 1 of the location of the first character of the first occurrence of str1.

&isin str1 str2

Returns `0` if case insensitive string str1 does not exists in string str2. Otherwise the function returns the character position + 1 of the location of the first character of the first occurrence of str1.

&rsin str1 str2

Returns `0` if string str1 does not exists in string str2. Otherwise the function returns the character position + 1 of the location of the first character of the last occurrence of str1.

&risin str1 str2

Returns `0` if case insensitive string str1 does not exists in string str2. Otherwise the function returns the character position + 1 of the location of the first character of the last occurrence of str1.

## EXAMPLE

The &sin and similar functions are useful for two different purposes. Consider the following example, this utilizes &sin in two different contexts. `!while &not &sin @wc " \t\n"` is a test for the end of the number, i.e. a white space character (`<tab>`, `<SPACE>` or `<NL>`).

The invocation `set-variable #l1 &isin @wc "0123456789abcdef"` is subtly different. In this case the return value is used to convert the character to it's integer hex value by using the value returned by &isin.

    ;
    ; calc-hexnum
    ; Convert the sting from the current position in the buffer
    ; to a hexadecimal number.
    define-macro calc-hexnum
        forward-delete-char
        forward-delete-char
        set-variable #l0 0
        !while &not &sin @wc " \t\n"
            set-variable #l1 &isin @wc "0123456789abcdef"
            !if &not #l1
                ml-write "Bad Hex number found"
                !abort
            !endif
            set-variable #l0 &mul #l0 16
            set-variable #l0 &add #l0 &sub #l1 1
            forward-delete-char
        !done
        insert-string #l0
    !emacro

The &rsin function is very similar to sin except the value return is the position of the last occurrence of the string in the given string instead of the first. This is particularly useful when extracting the path or file name from a complete file name. For example, given a UNIX style file name such as `"/usr/local/bin/me"` the path can be obtained using `set-variable %path &lef %pathfile &rsin` `"/" %pathfile` and the file name by using `set-variable %file &rig %pathfile &rsin` `"/" %pathfile`

## SEE ALSO

Operating Modes, Variable Functions, &sequal(4), &rep(4).

(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12

</HMTL>