PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > sprintf percent sign problem
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
sprintf percent sign problem

Réponse
 
LinkBack Outils de la discussion
Vieux 04/11/2007, 08h38   #1
mpthimios@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sprintf percent sign problem

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.

  Réponse avec citation
Vieux 04/11/2007, 09h08   #2
bbxx789_05ss@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sprintf percent sign problem

Efthimios Bothos 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).
>


I'm not seeing that:

str = "hello%world"
new_str = sprintf('%20s', str)
puts new_str

--output:--
hello%world


It's always baffling to me why a poster doesn't just post a simplified
example along with the error.
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 04/11/2007, 19h15   #3
gilesb@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sprintf percent sign problem

> It's always baffling to me why a poster doesn't just post a simplified
> example along with the error.


If they knew to provide tests, they wouldn't be asking syntax
questions in the first place. That's an experienced programmer's rule,
and syntax questions usually come from newbies.

It is a very good idea to provide test cases in responses, though.
Apart from anything else, whenever I do that I go into IRB and half
the time find out something more interesting than whatever I was going
to say.

--
Giles Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h52.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07724 seconds with 11 queries