Removing characters from TextField

Not the AppleScript…it’s the meat of my application.

So, I’ve got the apostrophes working with the code that Tim had, I just want to prevent a person from accidentally typing in only one double quote and having it break.

So, either we have to have code that strips the stray double quote (ideally, since it won’t be needed when recorded) or code that prompts the user not to use double quotes.

I can do the latter, but if there is a simple way to strip a stray double quote that would be best.

You can prevent the user from typing a double quote by catching it in the KeyDown event and returning True.

if Key = ChrB(34) then return true

That won’t work if the user pastes.

This is tough without seeing your code because we’re obviously having a communication issue, so let me try it this way. When you want to send a parameter to the shell, is usually has to be escaped some way so that the shell knows it is one string and not special characters. There are a couple of ways to do that.

The first is to escape each character that might cause a problem. Offhand, that includes a space, single-quote, or double-quote. So let’s say you were sending the parameter to echo (which doesn’t need to be escaped, but we’ll pretend here that it does), and let’s say the parameter is the title is "don't say". The escaped version of that using this method would be the\\ title\\ is\\ \"don\\'t\\ say\". That will work, but there are more characters than those that will cause an issue, so I find it impractical.

The second method (the one I recommend) is to quote the parameter in single-quotes. This works for every character that follows except for the single-quote, so those have to be dealt with by closing the quotes, escaping the single-quote, then reopening the quote. In this case, my example would look like this: 'the title is "you don'\\''t say"'.

AppleScript will actually do this for you. If you send your raw string (the one the user entered) from Xojo to your AppleScript, let’s say as value, you can do something like this:

set value to quoted form of value
do shell script "myCommand " & value

The AppleScript command quoted form of will insert the single-quotes into the right places, ready to send to the shell.

I’ve tried using the quoted form in the AppleScript for this variable, and it still doesn’t work.

I’ve never had issues with my textfield strings in this app with spaces. Just stray single and double quotes.

I’ve gotten the single quote taken care of.

Isn’t there something simple I can use with ReplaceAll(TextField1.text) that will simply strip out any double quotes? Surely, this must be simple to do.

s = TextField1.Text.ReplaceAll( """", "" )

This works great! Thanks everyone for helping!

[code] dim answer as string

    // Remove Double Quotes
    answer = TextField1.Text.ReplaceAll( """", "" )
    
    //Escape Single Quotes
    answer = answer.ReplaceAll( "'", "\\'" )
    answer = "'" + answer + "'"
    [/code]