Parameters
stringExpression1
stringExpression2
stringExpression1
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.
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".
This handler finds all instances of the string represented by
represented by
input
-- Lingo syntax
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
// JavaScript syntax
function SearchAndReplace(input, stringToFind, stringToInsert) {
output = "";
findLen = stringToFind.length - 1;
do {
currOffset = offset(stringToFind, input);
output = output + input.char[0..currOffset];
output = output.substr(0,output.length-2);
output = output + stringToInsert;
input = input.substr(currOffset+findLen,input.length);
} while (input.indexOf(stringToFind) >= 0);
output = output + input;
return output;
}
See also
chars(), length(), contains,
434
Chapter 12: Methods
Required. Specifies the sub-string to search for in
Required. Specifies the string that contains the sub-string
.
and replaces them with the string represented by
starts
stringExpression2
within the string
stringToFind
stringToInsert
.
:
Need help?
Do you have a question about the DIRECTOR MX 2004-DIRECTOR SCRIPTING and is the answer not in the manual?
Questions and answers