strrindex
Prev | Orchestra Opcodes and Operators | Next

## strrindex

strrindex — Return the position of the last occurence of a string in another string

## Description

Return the position of the last occurence of S2 in S1, or -1 if not found. If S2 is empty, the length of S1 is returned. strrindex runs at init time only.

## Syntax

    ipos strrindex S1, S2

## Examples

Here is an example of the strrindex opcode. It uses the file strrindex.csd.

Example 863. Example of the strrindex opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -n    ;;;no sound output
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    </CsOptions>
    <CsInstruments>
    ;example by Joachim Heintz

      opcode FilNam, S, S
    ;returns the name of a file path
    Spath  xin
    ipos   strrindex Spath, "/"	;look for the rightmost '/'
    Snam   strsub    Spath, ipos+1	;extract the substring
           xout      Snam
      endop

    instr name
           prints    "Printing name:\n"
    Snam   FilNam    "/my/dir/my/file.WAV"
           puts      Snam, 1

    endin
    </CsInstruments>
    <CsScore>
    i "name" 0 0
    e
    </CsScore>
    </CsoundSynthesizer>

## See also

strrindexk

## Credits

Author: Istvan Varga
2006

New in version 5.02

Prev | Up | Next
strlowerk | Home | strrindexk