Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Replacing typographer's quotes in Javascript

Explorer ,
Nov 17, 2010 Nov 17, 2010

Maybe my newness to Javascript has me thinking down the wrong path, but I thought I could just take a text string and run:

calloutText = calloutText.replace(/"/g, "\'");

and replace a double quote with a single quote. This works for simple quotes, but not for typographer's quotes. Is the manner of addressing curly quotes so obscure and variable that one must resort to the find object for handling this? I haven't seen this particular discussion in the forum.

TOPICS
Scripting
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Nov 18, 2010 Nov 18, 2010
calloutText = c.replace(/(“|”)/g, "'");

If you want to find quotes, you have to type them in the 1st parameter -- Alt+147 and Alt+148 characters (on Windows) -- instead of double quotes. In the 2nd parameter,  you don't need escape the single quote inside  the double quotes.

Kasyan

Translate
Valorous Hero ,
Nov 18, 2010 Nov 18, 2010
calloutText = c.replace(/(“|”)/g, "'");

If you want to find quotes, you have to type them in the 1st parameter -- Alt+147 and Alt+148 characters (on Windows) -- instead of double quotes. In the 2nd parameter,  you don't need escape the single quote inside  the double quotes.

Kasyan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2010 Nov 18, 2010

-- The reason for this is that InDesign's Find & Change translates between straight double quotes and curly quotes, just for your convenience, but your code uses native Javascript and that doesn't do the auto-translate.

Kasyan's Find string contains the actual characters you should be searching for.

(On that note: I had a spot of trouble trying to use Unicode notation in a GREP string inside a Javascript -- I should look it up, but from memory I think \uXXXX didn't work. Is that because regexp-inside-js is another language altogether?)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 18, 2010 Nov 18, 2010

Thanks, Kasyan, that was the clue I needed. I found that on my keyboard (Windoze) I have to make the key code four digits to show the correct quote, i.e.:

alt+ 0147: “ = left curly double quote
alt+ 0148: ” = right curly double quote
alt+ 0149: • = bullet character
alt+ 0145: ‘ = left curly single quote
alt+ 0146: ’ = right curly single quote, etc.


I wonder if there's a convenient reference to these key codes somewhere. I did a bit of searching and didn't find it. The ID CS4 manual lists all keyboard shortcuts, but has next to nothing on these key codes. No doubt they vary depending on the font's character set...

Thanks for your observations as well, Jongware. I'd like to see the answer to your question as well.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 19, 2010 Nov 19, 2010
I wonder if there's a convenient reference to these key codes somewhere.

I use Character Map application to find Alt key numeric codes. I am sure in Google you can find a lot of such references -- here is my first hit.

Kasyan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 19, 2010 Nov 19, 2010
LATEST

> I use *Character Map* application to find Alt key numeric codes.

Excellent, Kasyan, thanks. Turns out my machine didn't have Character
Map installed, but it does now. It's always a marvel how much difference it
makes to have the precise terminology.

Daniel

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines