DSSSL Library Reference: Part of the Modular DocBook Stylesheet distribution
Prev |  | Next

# string-index

## Name

string-index -- Finds first occurance of 'target' in 'source'

## Synopsis

    (string-index source target)

## Description

Returns the position of the first occurance of `target` in `source`, or -1 if it does not occur.

## Author

Norman Walsh, <ndw@nwalsh.com>

## Source Code

    (define (string-index source target)
      ;; Finds first occurance of 'target' in 'source'
      (let loop ((str source) (pos 0))
        (if (< (string-length str) (string-length target))
    	-1
    	(if (string=? (substring str 0 (string-length target)) target)
    	    pos
    	    (loop (substring str 1 (string-length str))
    		  (+ pos 1))))))

Prev | Home | Next
trim-string | Up | parse-pi-attribute