on fnd(srcData, fndSpec, caseFlag, allOccurrencesFlag)
try
set fndResult to find text fndSpec ¬
in srcData case sensitive caseFlag all occurrences allOccurrencesFlag ¬
with regexp and string result
return fndResult
on error # errMsg number errNum
set fndResult to false
return fndResult
end try
end fnd
-- ======================================================================
-- You can easily make the find handler fail silently.
-- ======================================================================
on fnd(srcData, fndSpec, caseFlag, allOccurrencesFlag)
try
set fndResult to find text fndSpec ¬
in srcData case sensitive caseFlag all occurrences allOccurrencesFlag ¬
with regexp and string result
end try
end fnd
-- ======================================================================
on fndUsing(srcData, fndSpec, usingSpec, caseFlag, allOccurrencesFlag)
try
set fndResult to find text fndSpec ¬
in srcData case sensitive caseFlag all occurrences allOccurrencesFlag ¬
using usingSpec with regexp and string result
return fndResult
on error # errMsg number errNum
return false
end try
end fndUsing
-- ======================================================================
on cng(srcData, fndStr, cngStr, caseFlag)
set theResult to change fndStr into cngStr in srcData case sensitive caseFlag with regexp
end cng
-- ======================================================================
You can also do a mass change like this:
set fileName to "some-File_Name"
set newFileName to change {"-", "_"} into {" ", " "} in fileName
I use Script Debugger's built-in Text Substitution to quickly drop in handler calls, although I used to use TypeIt4Me for this. Such utilities are indispensable in my opinion.