special characters screwing up string operations

A

Aryk Grosz

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?
 
R

Robert Dober

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

=93 =96

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.
 
P

Pascal J. Bourguignon

Aryk Grosz said:
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?

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)
 
R

Robert Dober

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. ;)
R.

(1) He is not the only one.
--=20
Si tu veux construire un bateau ...
Ne rassemble pas des hommes pour aller chercher du bois, pr=E9parer des
outils, r=E9partir les t=E2ches, all=E9ger le travail=85 mais enseigne aux
gens la nostalgie de l=92infini de la mer.

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

Eric Hodel

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

=93 =96

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?

My console doesn't allow me to paste these characters into irb (OS X, =20=

it beeps when I try) so I think it is Readline's fault.

I can read them with gets:

$ ruby -e 'p gets'
=93 =96
"\342\200\234 \342\200\223\n"

You'll probably need to adjust your terminal settings to accept these =20=

characters.=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top