BBEdit format problem

Hi all.
I’ preparing a script that download a source page, serching and replacing some part of text and uploading it into a web server.

I have a problem: I use BBEdit for serching and replacing strings (BBEdit have a powerfull function of serching with grab). Sometimes, if the page have a strange charters, BBedit give me an error when the script tries to open the file. BBedit says me that the file may be damaged (!) but the only question is that the file contains some strange charters.

Strange charters are not important, but the advice break the script!!!

Can someone help me?

You could do the search and replace directly in the AppleScript. Set the curl output to a variable and then use a handler like this acting on theText (or whatever you call it). The text returned from the handler will have the replacement:

to findAndReplace(toFind, toReplace, theText)
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to toFind
	set textItems to theText's text items
	set AppleScript's text item delimiters to toReplace
	tell textItems to set editedText to beginning & toReplace & rest
	set AppleScript's text item delimiters to astid
	return editedText
end findAndReplace