Hello All, I am very new to ruby.I have a small doubt. suppose i have a string called ''add'',I want this to get saved when given in any of the following conditions like "ADD" ''aDD'' ''Add'' it should be converted back in to small case and displayed back how can i achieve this Thanks Jagan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Better you use downcase method of String class. Example: str = "AdD" str.downcase #=> "add" the downcase method will convert the upper case letters to lower case. For you reference : http://www.ruby-doc.org/core/classes/String.html#M000809 Regards, - Karthi Jagan wrote:> Hello All, > > > > I am very new to ruby.I have a small doubt. > > suppose i have a string called ''add'',I want this to get saved when > given in any of the following conditions > > like > > "ADD" > ''aDD'' > ''Add'' > > > it should be converted back in to small case and displayed back > > how can i achieve this > > > Thanks > Jagan-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 29, 2007, at 3:24 AM, Jagan wrote:> suppose i have a string called ''add'',I want this to get saved when > given in any of the following conditions > > like > > "ADD" > ''aDD'' > ''Add'' > > it should be converted back in to small case and displayed back > > how can i achieve thisuse .downcase http://www.ruby-doc.org/docs/ProgrammingRuby/html/ ref_c_string.html#String.downcase -- def gw acts_as_n00b writes_at(www.railsdev.ws) end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
string.downcase returns the downcased version of the string - it does not affect the source object. If you want that reference to become downcase you need str = "ADD" str = str.downcase str.downcase will do what it''s supposed to, but str will still be whatever it was originally. If you''re new to OO programming this one can really confuse you. On Nov 29, 11:39 am, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote:> On Nov 29, 2007, at 3:24 AM, Jagan wrote: > > > suppose i have a string called ''add'',I want this to get saved when > > given in any of the following conditions > > > like > > > "ADD" > > ''aDD'' > > ''Add'' > > > it should be converted back in to small case and displayed back > > > how can i achieve this > > use .downcase > > http://www.ruby-doc.org/docs/ProgrammingRuby/html/ > ref_c_string.html#String.downcase > > -- > def gw > acts_as_n00b > writes_at(www.railsdev.ws) > end--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---