Lingo Dictionary > O-R > offset() (string function) |  |

offset() (string function)

Syntax

    offset(stringExpression1, stringExpression2)

Description

Function; returns an integer indicating the position of the first character of `stringExpression1` in `stringExpression2`. This function returns 0 if `stringExpression1` is not found in `stringExpression2`. Lingo counts spaces as characters in both strings.

On the Macintosh, the string comparison is not sensitive to case or diacritical marks. For example, Lingo considers a and Å to be the same character on the Macintosh.

Example

This statement displays in the Message window the beginning position of the string "media" within the string "Macromedia":

    put offset("media","Macromedia")

The result is 6.

Example

This statement displays in the Message window the beginning position of the string "Micro" within the string "Macromedia":

    put offset("Micro", "Macromedia")

The result is 0, because "Macromedia" doesn't contain the string "Micro".

Example

This handler finds all instances of the string represented by `stringToFind` within the string represented by `input` and replaces them with the string represented by `stringToInsert`.

    on SearchAndReplace input, stringToFind, stringToInsert
    	output = ""
    	findLen = stringToFind.length - 1
    	repeat while input contains stringToFind
    		currOffset = offset(stringToFind, input)
    		output = output & input.char [1..currOffset]
    		delete the last char of output
    		output = output & stringToInsert
    		delete input.char [1.. (currOffset + findLen)]
    	end repeat
    	set output = output & input
    	return output
    end

See also

`chars()`, `length()`, `contains`, `starts`