Special characters screwing up string operations

Im doing some manipulation of strings, and there are some characters
that Ruby just really does not like:

“ –

If you try to paste these into a Ruby console the cursor will jump
around. Likewise, if you put it in a string and try to do text[5,4] it
will give you the wrong piece of the text.

How do I get around this. Is there some special escape command or do I
just have to gsub these characters?

On Tue, Apr 21, 2009 at 9:41 PM, Aryk G. [email protected]
wrote:

Im doing some manipulation of strings, and there are some characters
that Ruby just really does not like:

“ –

If you try to paste these into a Ruby console the cursor will jump
around. Likewise, if you put it in a string and try to do text[5,4] it
will give you the wrong piece of the text.
With the information at hand it might be an encoding issue,
what version are you using, please paste the output of ruby -v
R.

Aryk G. [email protected] writes:

just have to gsub these characters?
Perhaps you could try a real programming language?

C/USER[1]> (length “abcde\“\ \–fgh”)
11
C/USER[2]> (subseq “abcde\“\ \–fgh” 5 6)
““”
C/USER[3]> (subseq “abcde\“\ \–fgh” 5 9)
““ –f”
C/USER[4]> (map 'list (function char-code) “abcde“ –fgh”)
(97 98 99 100 101 8220 32 8211 102 103 104)

On Apr 21, 2009, at 12:41, Aryk G. wrote:

just have to gsub these characters?
My console doesn’t allow me to paste these characters into irb (OS X,
it beeps when I try) so I think it is Readline’s fault.

I can read them with gets:

$ ruby -e ‘p gets’
“ –
“\342\200\234 \342\200\223\n”

You’ll probably need to adjust your terminal settings to accept these
characters.

On Tue, Apr 21, 2009 at 10:55 PM, Pascal J. Bourguignon
[email protected] wrote:

Perhaps you could try a real programming language?
Adam do not pay attention, Pascal is convinced that CL is a real
programming language. (1)
Never mind, he is a nice guy, just suffering from parenoia. :wink:
R.

(1) He is not the only one.

Si tu veux construire un bateau …
Ne rassemble pas des hommes pour aller chercher du bois, préparer des
outils, répartir les tâches, alléger le travail… mais enseigne aux
gens la nostalgie de l’infini de la mer.

If you want to build a ship, don’t herd people together to collect
wood and don’t assign them tasks and work, but rather teach them to
long for the endless immensity of the sea.