# Smart Quotes

**URL:** <https://rubytalk.org/t/smart-quotes/12056>\
**Category:** ruby-talk\
**Created:** [11 June 2004 14:27 UTC](https://rubytalk.org/t/smart-quotes/12056 "2004-06-11T14:27:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Warren\_Brown2](https://avatars.discourse-cdn.com/v4/letter/w/f17d59/32.png) [@Warren\_Brown2](https://rubytalk.org/u/Warren_Brown2)\
**Post date:** [11 June 2004 14:27 UTC](https://rubytalk.org/t/smart-quotes/12056/1 "2004-06-11T14:27:35Z")

</div>

Martin,

> > Trying to save myself a bit of tedium - has anyone  
> > already written code to replace smart quotes and  
> > other such extensions with their normal ascii  
> > equivalents?

> FWIW, pasting into vim and typing 'show ascii' gives  
> Hex93 for the open " and Hex94 for the close one - I  
> was hoping someone had already written a tr string  
> to do the lot (there's an ellipsis, an en- and  
> em-dash, and a few other punctuation marks too).

&nbsp;&nbsp;&nbsp;&nbsp;Well, from your description, it looks like you are using the  
"Windows Western" character set. If so, it's easy enough to generate  
the String#tr parameters. Window's character map, set to Windows  
Western encoding reveals:

&nbsp;&nbsp;&nbsp;&nbsp;0x85 - Ellipsis  
&nbsp;&nbsp;&nbsp;&nbsp;0x91 - Left single quote  
&nbsp;&nbsp;&nbsp;&nbsp;0x92 - Right single quote  
&nbsp;&nbsp;&nbsp;&nbsp;0x93 - Left double quote  
&nbsp;&nbsp;&nbsp;&nbsp;0x94 - Right double quote  
&nbsp;&nbsp;&nbsp;&nbsp;0x96 - En dash  
&nbsp;&nbsp;&nbsp;&nbsp;0x97 - Em dash

&nbsp;&nbsp;&nbsp;&nbsp;You can look up any other punctuation characters yourself.

&nbsp;&nbsp;&nbsp;&nbsp;The String#tr call would be something like:

x = "\x91\x92\x93\x94\x96\x97"  
x.tr("\x91\x92\x93\x94\x96\x97","''\"\"\-")  
=\> "''\"\"--"

&nbsp;&nbsp;&nbsp;&nbsp;Be careful with the "-" in the second parameter. "-" is used to  
indicate ranges in String#tr. By placing the "-" at the end of the  
string, we force String#tr to interpret it as a character instead of a  
range, and we also take advantage of the fact that String#tr replicates  
the last character of the second parameter to make the string as long as  
the first parameter.

&nbsp;&nbsp;&nbsp;&nbsp;I'm not sure what you want to change an ellipsis to, my preference  
would be "...", but that would require a separate  
String#gsub("\x85","...").

&nbsp;&nbsp;&nbsp;&nbsp;I hope this helps.

&nbsp;&nbsp;&nbsp;&nbsp;- Warren Brown

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello1](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@Martin\_DeMello1](https://rubytalk.org/u/Martin_DeMello1)\
**Post date:** [12 June 2004 15:58 UTC](https://rubytalk.org/t/smart-quotes/12056/2 "2004-06-12T15:58:44Z")

</div>

[snip]

Thanks!

martin

> **···**
>
> Warren Brown \<WBrown@isoft.com\> wrote:
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;Well, from your description, it looks like you are using the  
> > "Windows Western" character set. If so, it's easy enough to generate  
> > the String#tr parameters. Window's character map, set to Windows  
> > Western encoding reveals:
