|
replace escape characters
Added on 5/25/2001
|
Send this some text and it will give you the text back with the escaped '\' characters switched. Current supports \n - RETURN \t - TAB \q - QUOTE Others can be easily added in the case statement.
This really isn't a behavior but rather a utility for text that should be placed in a movie script.
on replaceEscapeChars theText
if stringP(theText) = 1 then
-- save the old itemDelimiter and replace it with "\"
oldDelimiter = the itemDelimiter
the itemDelimiter = "\"
newText = theText.item[1]
numItems = theText.item.count
repeat with i = 2 to numItems
currentItem = theText.item[i]
specialChar = ""
-- figure out which char it is
escapedChar = currentItem.char[1]
case escapedChar of
"n":
specialChar = RETURN
"t":
specialChar = TAB
"q":
specialChar = QUOTE
end case
-- put it together
currentItem = currentItem.char[2..currentItem.char.count]
newText = newText & specialChar & currentItem
end repeat
-- restore the itemDelimiter
the itemDelimiter = oldDelimiter
-- return the new string
return newText
else
-- return theText if its not a string
return theText
end if
end
|
|