Director Code Snippets
Some useful functions and code snippets for use in your Director Lingo programming.
- String Functions 1 (this page)
- MIAW Functions 1 (...coming)
- FILE Functions 1 (...coming)
Strip a character from a string
Usage: var=Strip(Source_String, Character_to_Strip)
on strip theString, theCharacter
--put the paramcount
if theString = void
or the paramCount<>
2 then
put "usage:
strip(theSting, theCharacter)"
exit
end if
theLength = length(theString)
retString = ""
repeat with
i = 1 to thelength
if theString.char[i]
<> theCharacter then
put theString.char[i]
after retString
end if
end repeat
return retString
end

Left string function
Return the left n characters of a string
Usage: var=LeftStr(Source_String, Number_of_characters)
on leftStr theString,
howmany
if theString = void
then
put "usage:
leftStr(theSting, howmany)"
exit
end if
theLength = length(theString)
if howMany > theLength then
howMany = theLength
end if
return theString.char[1..howmany]
end

Right string function
Return the right n characters of a string
Usage: var=rightStr(Source_String, Number_of_characters)
on rightStr theString,
howmany
if theString = void
then
put "usage:
rightStr(theSting, howmany)"
exit
end if
theLength = length(theString)
if howMany > theLength then
howMany = theLength
end if
return theString.char[howmany..theLength]
end

Mid string function
Returns a substring from a string, given the starting offset and the number of characters.
Usage: var=midStr(Source_String, startOffset, Number_of_characters)
on midStr theString,
start, howmany
if theString = void
then
put "usage:
midStr(theSting, start, howmany)"
exit
end if
theLength = length(theString)
endPoint = start + howmany
if endPoint > theLength then
endPoint = theLength
end if
a=theString.char[start..endPoint]
return a
end

