Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to make command to replace single quote with two single quotes and vice versa #14

Closed
gooddadmike opened this issue Jul 24, 2019 · 2 comments

Comments

@gooddadmike
Copy link

I'm doing a lot of database word where I'm passing some dynamic sql.

CASE WHEN [t].[VALUE] = 'Foo' THEN NULL ELSE 'Bar' END

and I often need to reverse it from '' to ' as well.

I have tried it this way

copyq:
function modifyText(text)
{
  // TODO: Modify text here!
  return text.replace("'", "''")
}

if (!copy())
  abort()

var text = str(clipboard())
var newText = modifyText(text)
if (text == newText)
  abort();

copy(newText)
paste()

and it only replaces the very first ' with ''. It never gets them both. Any help appreciated.

@garulovilla
Copy link
Contributor

You need to use a regex text.replace(/'/g, "''"). If you don't use a regex only the first occurrence is replaced. Yo can check the documentation in String.prototype.replace().

@gooddadmike
Copy link
Author

This solved me up. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants