Ask a Question related to Ruby, Design and Development.
-
Paul Rubel #1
gsub(/\s*$/, "") doubling string
Hello,
I recently downloaded ruby 1.8.0 p3, (2003-06-23) [i686-linux], and
tried it on some code that chopped trailing spaces from a string using
gsub(/\s*$/, ""). I'm seeing some odd behavior and was hoping someone
could shed some light on what's happening.
In 1.6.7 the code above did what I expected. However, in 1.8.0p3 it
seems to double the string if the string doesn't end in a space.
#does what I expected in 1.6 and 1.8
irb(main):004:0> " TEST ".gsub(/\s*$/, "")
=> " TEST"
# very odd (at least to me) in 1.8.0p3
irb(main):005:0> " TEST .".gsub(/\s*$/, "")
=> " TEST . TEST ."
Where does this repeat come from? If I change the * to a + it fixes my
problem but I was hoping someone could help explain why it's happening.
While looking into this I've noticed that there seems to be something
special about 2 repeats.
irb(main):002:0> " string ".gsub(/\s*$/, 'P')
" stringPP"
Regardless of how many trailing spaces I add two Ps are always
appended. It seems that one matches all the spaces and then one matches
the zero length string that's the end itself since a string without
trailing spaces puts in one P. Is the $ getting used twice in this
match?
I'd appreciate any explanations or help.
thank you,
Paul
Paul Rubel Guest
-
"Error Creating Control" and "Cast from String"
I'm creating a custom date control. In appearance, it's just a textbox and a button. It has three custom properties: CalDate, CalDateType and... -
#26292 [Opn->Bgs]: substr returns "0" for any offset on the string "0"
ID: 26292 Updated by: sniper@php.net Reported By: ravacholp at hotmail dot com -Status: Open +Status: ... -
#25763 [Opn->WFx]: Why the string "1.10" is equal to the string "1.1"?
ID: 25763 Updated by: pollita@php.net Reported By: jparneodo at yahoo dot fr -Status: Open +Status: ... -
#25763 [NEW]: Why the string "1.10" is equal to the string "1.1"?
From: jparneodo at yahoo dot fr Operating system: RH7.2 PHP version: 4.3.3 PHP Bug Type: Strings related Bug description: ... -
convert visual basic "string" data type to DB2 "blob"
Does anyone know if a visual basic string data type can be converted to DB2 blob datatype? I have all data in XML files and I use Visual Basic to... -
Kurt M. Dresner #2
Re: gsub(/\s*$/, "") doubling string
I don't know what the problem is, but you should probably be using
gsub(/\s+$/,'') anyway :o)
-Kurt
On Tue, Jul 22, 2003 at 03:36:56AM +0900, Paul Rubel wrote:> Hello,
> I recently downloaded ruby 1.8.0 p3, (2003-06-23) [i686-linux], and
> tried it on some code that chopped trailing spaces from a string using
> gsub(/\s*$/, ""). I'm seeing some odd behavior and was hoping someone
> could shed some light on what's happening.
>
> In 1.6.7 the code above did what I expected. However, in 1.8.0p3 it
> seems to double the string if the string doesn't end in a space.
>
> #does what I expected in 1.6 and 1.8
> irb(main):004:0> " TEST ".gsub(/\s*$/, "")
> => " TEST"
>
> # very odd (at least to me) in 1.8.0p3
> irb(main):005:0> " TEST .".gsub(/\s*$/, "")
> => " TEST . TEST ."
>
> Where does this repeat come from? If I change the * to a + it fixes my
> problem but I was hoping someone could help explain why it's happening.
>
> While looking into this I've noticed that there seems to be something
> special about 2 repeats.
>
> irb(main):002:0> " string ".gsub(/\s*$/, 'P')
> " stringPP"
>
> Regardless of how many trailing spaces I add two Ps are always
> appended. It seems that one matches all the spaces and then one matches
> the zero length string that's the end itself since a string without
> trailing spaces puts in one P. Is the $ getting used twice in this
> match?
>
> I'd appreciate any explanations or help.
> thank you,
> Paul
>
>======= End of Original Message =======<Kurt M. Dresner Guest
-
Yukihiro Matsumoto #3
Re: gsub(/\s*$/, "") doubling string
Hi,
In message "Re: gsub(/\s*$/, "") doubling string"
on 03/07/22, ts <decoux@moulon.inra.fr> writes:
|P> # very odd (at least to me) in 1.8.0p3
|P> irb(main):005:0> " TEST .".gsub(/\s*$/, "")
|P> => " TEST . TEST ."
|
| Can you try this
Thank you for the fix, Guy. And thank you for finding a bug, Paul.
|P> irb(main):002:0> " string ".gsub(/\s*$/, 'P')
|P> " stringPP"
|
| this is normal
The first try replaces all trailing spaces with "P", then second try
replaces empty at the end of string with "P".
matz.
Yukihiro Matsumoto Guest



Reply With Quote

