On Dec 30, 2007 3:11 AM, Pavel Pvl <> wrote:
> seems to me as though I'm redundant on this forum...
>
>
> well anyway, doing '@@@@'.sub('@','#')
>
> returns
> '/#@@@'
It should return "\#@@@" (backslash before a character inside a double
quoted string is an escaped character). You are looking at the
general string representation of '#@@@'. Do this to see what I mean
...
irb> '@@@@'.sub('@', '#').each_byte { |b| puts b }
When you use 1.8 you see 4 integers, the first one the byte code for
the # sign, the others for the @ sign. I think 1.9 is the same way
with #each_byte, but haven't tried it out.
>
> how can I make it so that it doesn't through in the / ?
irb> puts '@@@@'.sub('@', '#')
>
> using 1.9 btw
>
> gsub doesn't do that, but I specifically ned sub to do that.
'####' is not special and doesn't need to be escaped.
The character sequence '#@' is because it is a short hand way of
"exploding" a class variable inside a String.
>
> ty
> --
> Posted via http://www.ruby-forum.com/.
hth,
Todd