Replace an apostrophe in a text string?

I am having problems using the Keystroke command when the text variables I am trying to Keystroke contain an apostrophe. How could I find and delete the apostrophe in a text string? I have searched the site and found several methods of replacing illegal characters, but none of them allow me to designate a ’ as the character I want to replace. Any help much appreciated. Thanks.

set x to "that's it."
set y to offset of "'" in x
set replacement to "*"
set z to (text 1 thru (y - 1) of x) & replacement & (text (y + 1) thru -1 of x)
display dialog z

By the way, this produces a text file with “that’s it” in it:

set x to "that's it."
set y to offset of "'" in x
set replacement to "*"
set z to (text 1 thru (y - 1) of x) & replacement & (text (y + 1) thru -1 of x)
display dialog z

tell application "TextEdit"
	activate
	tell application "System Events"
		keystroke x
		
	end tell
	
end tell

Alternatively:

set example to "That's it."
set example to replaceText("'", "", example)

on replaceText(find, replace, someText)
	set prevTIDs to text item delimiters of AppleScript
	set text item delimiters of AppleScript to find
	set someText to text items of someText
	set text item delimiters of AppleScript to replace
	set someText to "" & someText
	set text item delimiters of AppleScript to prevTIDs
	return someText
end replaceText

See also: replaceText

Thanks for the help, that worked great. As it turns out, Filemaker seems to export an odd character to it’s tab-delimited text files instead of a regular single-quote apostrophe. This is what I ended up using to fix it. Keystroke will give you strange results when typing that “bad” single-quote.

repeat while textvariable contains "'"
set y to offset of "'" in textvariable 
set replacement to "'"
set textvariable to (text 1 thru (y - 1) of textvariable) & replacement & (text (y + 1) thru -1 of textvariable)
end repeat

Thanks again.

It’s not and odd character, it’s the perfectly correct curly one.
Alas, System Events’s keystroke treats it badly (even under 10.4.11 where it is coded $D5)

Yvan KOENIG (from FRANCE samedi 30 août 2008 12:30:28)