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 > "capitalize" also letters after "-" ?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
"capitalize" also letters after "-" ?

Réponse
 
LinkBack Outils de la discussion
Vieux 10/05/2008, 14h52   #1
Iñaki Baz Castillo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut "capitalize" also letters after "-" ?

Hi, I receive strings like:

content-language
accept-resource-priority

and I want to "capitalize" them in this way:

Content-Language
Accept-Resource-Priority

But String#capitalize method just capitalized first letter:

Content-language
Accept-resource-priority


Is there any "fast" method for what I want?
Yes, I could implement it extending String class or my own class < String, =
but=20
performance is very important and I'd prefer using a method written in C=20
(as "String#capitalized"). Does is exist?


Thanks a lot.


=2D-=20
I=C3=B1aki Baz Castillo

  Réponse avec citation
Vieux 10/05/2008, 15h33   #2
Harry Kakueki
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: "capitalize" also letters after "-" ?

On Sat, May 10, 2008 at 10:52 PM, I=F1aki Baz Castillo <ibc@aliax.net> wrot=
e:
> Hi, I receive strings like:
>
> content-language
> accept-resource-priority
>
> and I want to "capitalize" them in this way:
>
> Content-Language
> Accept-Resource-Priority
>
> But String#capitalize method just capitalized first letter:
>
> Content-language
> Accept-resource-priority
>
>
> Is there any "fast" method for what I want?
> Yes, I could implement it extending String class or my own class < String=

, but
> performance is very important and I'd prefer using a method written in C
> (as "String#capitalized"). Does is exist?
>
>
> Thanks a lot.
>
>
> --
> I=F1aki Baz Castillo
>
>

Is this too slow?

str =3D "accept-resource-priority"
p str.split(/-/).map {|x| x.capitalize}.join("-")

Harry

--=20
A Look into Japanese Ruby List in English
http://www.kakueki.com/ruby/list.html

  Réponse avec citation
Vieux 10/05/2008, 16h02   #3
Iñaki Baz Castillo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: "capitalize" also letters after "-" ?

El S=E1bado, 10 de Mayo de 2008, Harry Kakueki escribi=F3:
> On Sat, May 10, 2008 at 10:52 PM, I=F1aki Baz Castillo <ibc@aliax.net> wr=

ote:
> > Hi, I receive strings like:
> >
> > content-language
> > accept-resource-priority
> >
> > and I want to "capitalize" them in this way:
> >
> > Content-Language
> > Accept-Resource-Priority
> >
> > But String#capitalize method just capitalized first letter:
> >
> > Content-language
> > Accept-resource-priority
> >
> >
> > Is there any "fast" method for what I want?
> > Yes, I could implement it extending String class or my own class <
> > String, but performance is very important and I'd prefer using a method
> > written in C (as "String#capitalized"). Does is exist?
> >
> >
> > Thanks a lot.
> >
> >
> > --
> > I=F1aki Baz Castillo

>
> Is this too slow?
>
> str =3D "accept-resource-priority"
> p str.split(/-/).map {|x| x.capitalize}.join("-")


Hummm:

Benchmark.realtime { "accept".capitalize }
=3D> 2.21729278564453e-05

Benchmark.realtime { "accept".split('-').map {|w|=20
w.capitalize}.join('-') }
=3D> 3.69548797607422e-05





=2D-=20
I=F1aki Baz Castillo

  Réponse avec citation
Vieux 10/05/2008, 16h48   #4
Iñaki Baz Castillo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: "capitalize" also letters after "-" ?

El S=C3=A1bado, 10 de Mayo de 2008, David A. Black escribi=C3=B3:
> I have to express healthy skepticism as to whether performance is *so*
> critical that you can't just do:
>
> str.gsub!(/((^|-).)/) { $1.upcase }


Thanks, but it seems slower than using "split"/"join":

Benchmark.realtime { "accept-asdasd-qweqwe".split('-').map {|w|=20
w.capitalize}.join('-') }
=3D> 3.09944152832031e-05

Benchmark.realtime { "accept-asdasd-qweqwe".gsub!(/((^|-).)/) {=20
$1.upcase } }
=3D> 3.60012054443359e-05


> and if it is, then I'll express healthy skepticism as to whether or
> not Ruby is the right language for the job :-)


Good response


> I don't know of any C library that does the above, so if you need it,
> you should probably go ahead and write it. You can base it off
> rb_capitalize(_bang).


ok, I'll keep this as an alternative

Thanks a lot.



=2D-=20
I=C3=B1aki Baz Castillo

  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 17h11.


É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,10741 seconds with 12 queries