John Kopanas
2005-May-24 21:29 UTC
Capitalizing First Letter Of Each Word In Sentence of Header
I know there is a .capitalize method to capitalize first lettter of first word of sentence but do you guys know of an easy way to capitalize first letter of each word? Thanks Guys? :-)
Zach Thompson
2005-May-24 21:35 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
On May 24, 2005, at 2:29 PM, John Kopanas wrote:> I know there is a .capitalize method to capitalize first lettter of > first word of sentence but do you guys know of an easy way to > capitalize first letter of each word? > > Thanks Guys? :-)I did this in a recent script: class String def capitalize_words self.gsub(/(\w*)/) {|s| s.capitalize } end end Seems to do the trick... Zach
Ramin
2005-May-24 21:36 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
Use CSS =] On 5/24/05, Zach Thompson <zach-DZILUfagCPWukZHgTAicrQ@public.gmane.org> wrote:> > On May 24, 2005, at 2:29 PM, John Kopanas wrote: > > > I know there is a .capitalize method to capitalize first lettter of > > first word of sentence but do you guys know of an easy way to > > capitalize first letter of each word? > > > > Thanks Guys? :-) > > I did this in a recent script: > > class String > def capitalize_words > self.gsub(/(\w*)/) {|s| s.capitalize } > end > end > > Seems to do the trick... > > Zach > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- - Ramin http://www.getintothis.com/blog _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Duane Johnson
2005-May-24 21:42 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
Proving once again that Ruby is a versatile language: string = "a sentence to capitalize" string.split.collect { |w| w.capitalize }.join(" ") :) Duane Johnson (canadaduane) On May 24, 2005, at 3:35 PM, Zach Thompson wrote:> On May 24, 2005, at 2:29 PM, John Kopanas wrote: > > >> I know there is a .capitalize method to capitalize first lettter >> of first word of sentence but do you guys know of an easy way to >> capitalize first letter of each word? >> >> Thanks Guys? :-) >> > > I did this in a recent script: > > class String > def capitalize_words > self.gsub(/(\w*)/) {|s| s.capitalize } > end > end > > Seems to do the trick... > > Zach > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Nicolas Cavigneaux
2005-May-24 21:45 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
Le mardi 24 mai 2005 à 15:42 -0600, Duane Johnson a écrit :> Proving once again that Ruby is a versatile language: > > string = "a sentence to capitalize" > string.split.collect { |w| w.capitalize }.join(" ") > > :)I''m much for this one ! That''s my choice. -- Nicolas Cavigneaux | GPG KeyID : CFE76D24 nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org | http://www.bounga.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Rob Park
2005-May-24 21:47 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
On 5/24/05, John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> wrote:> I know there is a .capitalize method to capitalize first lettter of > first word of sentence but do you guys know of an easy way to > capitalize first letter of each word?Well, I would do this by splitting the string into an array of words, then lowercasing each word/uppercasing the first letter of each word. "foo BaR bAZ QUX".split.each {|str| str.capitalize! }.join(" ") => "Foo Bar Baz Qux" Of course this is a bit of a dirty hack and it will destroy the capitalization of acronyms, or any other names that require capitals other than the first letter. Not to mention that words like "is" or "an" will also be capitalized incorrectly. -- Urban Artography http://artography.ath.cx
Rob Park
2005-May-24 21:51 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
On 5/24/05, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> "foo BaR bAZ QUX".split.each {|str| str.capitalize! }.join(" ") > => "Foo Bar Baz Qux"Oh poo, somebody else beat me to it. -- Urban Artography http://artography.ath.cx
John Kopanas
2005-May-25 00:00 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
How would you got about that in CSS? On 24-May-05, at 5:36 PM, Ramin wrote:> Use CSS =] > > On 5/24/05, Zach Thompson <zach-DZILUfagCPWukZHgTAicrQ@public.gmane.org> wrote: On May 24, > 2005, at 2:29 PM, John Kopanas wrote: > > > I know there is a .capitalize method to capitalize first lettter of > > first word of sentence but do you guys know of an easy way to > > capitalize first letter of each word? > > > > Thanks Guys? :-) > > I did this in a recent script: > > class String > def capitalize_words > self.gsub(/(\w*)/) {|s| s.capitalize } > end > end > > Seems to do the trick... > > Zach > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > -- > - Ramin > http://www.getintothis.com/blog > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Florian Weber
2005-May-25 00:07 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
I found this nice snippet somewhere: class String def titlecase non_capitalized = %w{of etc and by the for on is at to but nor or a via} gsub(/\\b[a-z]+/){ |w| non_capitalized.include?(w) ? w : w.capitalize }.sub(/^[a-z]/){|l| l.upcase }.sub(/\\b[a-z][^\\s]*?$/){|l| l.capitalize } end end
Nathan Colgate Clark
2005-May-25 00:11 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
On 5/24/05, John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> wrote:> > How would you got about that in CSS?p { text-transform: capitalize; } _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
John Kopanas
2005-May-25 00:41 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
ahhh... perfect! On 24-May-05, at 8:11 PM, Nathan Colgate Clark wrote:> On 5/24/05, John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> wrote: > How would you got about that in CSS? > p { text-transform: capitalize; } > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Gavin Sinclair
2005-May-25 02:58 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
On Wednesday, May 25, 2005, 7:42:06 AM, Duane wrote:> Proving once again that Ruby is a versatile language:> string = "a sentence to capitalize" > string.split.collect { |w| w.capitalize }.join(" ")> :)That won''t play nicely with "a string to capitalise", which is obviously an edge case. But I like the gsub-based solution better. Gavin
Ramin
2005-May-25 03:10 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
Won''t work in IE, but here is the CSS p:*first*-*letter* { text-transform:*capitalize;* } On 5/24/05, John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> wrote:> > How would you got about that in CSS? > > On 24-May-05, at 5:36 PM, Ramin wrote: > > > Use CSS =] > > > > On 5/24/05, Zach Thompson <zach-DZILUfagCPWukZHgTAicrQ@public.gmane.org> wrote: On May 24, > > 2005, at 2:29 PM, John Kopanas wrote: > > > > > I know there is a .capitalize method to capitalize first lettter of > > > first word of sentence but do you guys know of an easy way to > > > capitalize first letter of each word? > > > > > > Thanks Guys? :-) > > > > I did this in a recent script: > > > > class String > > def capitalize_words > > self.gsub(/(\w*)/) {|s| s.capitalize } > > end > > end > > > > Seems to do the trick... > > > > Zach > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > -- > > - Ramin > > http://www.getintothis.com/blog > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- - Ramin http://www.getintothis.com/blog _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Chris Boone
2005-May-25 11:27 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
That should only capitalize the first letter of the paragraph. Apply text-transform: capitalize to plain old p, as someone already mentioned. On 5/24/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Won''t work in IE, but here is the CSS > > p:first-letter { > text-transform:capitalize; > } > > On 5/24/05, John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> wrote: > > How would you got about that in CSS? > > > > On 24-May-05, at 5:36 PM, Ramin wrote: > > > > > Use CSS =] > > > > > > On 5/24/05, Zach Thompson <zach-DZILUfagCPWukZHgTAicrQ@public.gmane.org> wrote: On May 24, > > > 2005, at 2:29 PM, John Kopanas wrote: > > > > > > > I know there is a .capitalize method to capitalize first lettter of > > > > first word of sentence but do you guys know of an easy way to > > > > capitalize first letter of each word? > > > > > > > > Thanks Guys? :-) > > > > > > I did this in a recent script: > > > > > > class String > > > def capitalize_words > > > self.gsub(/(\w*)/) {|s| s.capitalize } > > > end > > > end > > > > > > Seems to do the trick... > > > > > > Zach > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > -- > > > - Ramin > > > http://www.getintothis.com/blog > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > -- > - Ramin > http://www.getintothis.com/blog > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Chris Boone http://hypsometry.com/ : website edification http://uvlist.org/ : free classifieds for the Upper Valley
Ramin
2005-May-25 12:25 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
Oh, you''re right... that does do only the first letter.. sorry, I just copy pasted it from one my old projects. You want the entire text to be capitalized.. so in that case just do: p { text-transform: capitalize; } On 5/25/05, Chris Boone <hypsometry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > That should only capitalize the first letter of the paragraph. > > Apply text-transform: capitalize to plain old p, as someone already > mentioned. > > On 5/24/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Won''t work in IE, but here is the CSS > > > > p:first-letter { > > text-transform:capitalize; > > } > > > > On 5/24/05, John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> wrote: > > > How would you got about that in CSS? > > > > > > On 24-May-05, at 5:36 PM, Ramin wrote: > > > > > > > Use CSS =] > > > > > > > > On 5/24/05, Zach Thompson <zach-DZILUfagCPWukZHgTAicrQ@public.gmane.org> wrote: On May 24, > > > > 2005, at 2:29 PM, John Kopanas wrote: > > > > > > > > > I know there is a .capitalize method to capitalize first lettter > of > > > > > first word of sentence but do you guys know of an easy way to > > > > > capitalize first letter of each word? > > > > > > > > > > Thanks Guys? :-) > > > > > > > > I did this in a recent script: > > > > > > > > class String > > > > def capitalize_words > > > > self.gsub(/(\w*)/) {|s| s.capitalize } > > > > end > > > > end > > > > > > > > Seems to do the trick... > > > > > > > > Zach > > > > > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > > -- > > > > - Ramin > > > > http://www.getintothis.com/blog > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > > > > -- > > - Ramin > > http://www.getintothis.com/blog > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > -- > Chris Boone > > http://hypsometry.com/ : website edification > http://uvlist.org/ : free classifieds for the Upper Valley >-- - Ramin http://www.getintothis.com/blog _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Premshree Pillai
2005-May-25 12:42 UTC
Re: Capitalizing First Letter Of Each Word In Sentence of Header
Prolly very similar to what some of the folks posted: str = str.split(" ").map { |ele| ele = ele.capitalize }.join(" ") :-) On 5/25/05, John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> wrote:> I know there is a .capitalize method to capitalize first lettter of > first word of sentence but do you guys know of an easy way to > capitalize first letter of each word? > > Thanks Guys? :-) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Premshree Pillai http://www.livejournal.com/users/premshree/