[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

sprintf percent sign problem

mpthimios

11/4/2007 8:41:00 AM

Hi,
I am trying to format some text using sprintf. The text itself
contains the percent sign (%).

When I use it without any escape character, as expected ruby throws
error (unkonown format sequence).

When I use the "\%" sequence ruby complaints when the "\%" is
somewhere in the text. When it is at the end it works but I don't want
it there.

When I use the "%%" sequence, I get the exact sequence as output ("%%"
is printed!!)..
Has anyone observed this behavior? Am I doing something wrong or it is
a ruby bug?

Thanks in advance,
Efthimios.


2 Answers

7stud --

11/4/2007 9:10:00 AM

0

Duplicate post. See here:

http://www.ruby-...topic/...
--
Posted via http://www.ruby-....

Alex Young

11/4/2007 12:30:00 PM

0

mpthimios wrote:
> Hi,
> I am trying to format some text using sprintf. The text itself
> contains the percent sign (%).
>
> When I use it without any escape character, as expected ruby throws
> error (unkonown format sequence).
>
> When I use the "\%" sequence ruby complaints when the "\%" is
> somewhere in the text. When it is at the end it works but I don't want
> it there.
>
> When I use the "%%" sequence, I get the exact sequence as output ("%%"
> is printed!!).. >
> Has anyone observed this behavior? Am I doing something wrong or it is
> a ruby bug?

I don't see that:

irb(main):001:0> text = "foo%%bar"
=> "foo%%bar"
irb(main):002:0> sprintf(text)
=> "foo%bar"

--
Alex