434
Chapter 12: Methods
Parameters
stringExpression1
Required. Specifies the sub-string to search for in
stringExpression2
.
stringExpression2
Required. Specifies the string that contains the sub-string
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
stringToFind
within the string
represented by
input
and replaces them with the string represented by
stringToInsert
:
-- 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.. (curr 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 = input.char[0..currOffset];
output = output.substr(0,output.length-2);
output = stringToInsert;
input = input.substr(curfindLen,input.length);
} while (input.indexOf(stringToFind) >= 0);
output = input;
return output;
}
See also
chars()
,
length()
,
contains
,
starts
Summary of Contents for DIRECTOR MX 2004-DIRECTOR SCRIPTING
Page 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Page 48: ...48 Chapter 2 Director Scripting Essentials...
Page 100: ...100 Chapter 4 Debugging Scripts in Director...
Page 118: ...118 Chapter 5 Director Core Objects...
Page 594: ...594 Chapter 12 Methods...
Page 684: ...684 Chapter 14 Properties See also DVD...
Page 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Page 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Page 1102: ...1102 Chapter 14 Properties...