# Ruby Newbie-help regarding strings

**URL:** <https://www.ruby-forum.com/t/ruby-newbie-help-regarding-strings/121624>\
**Category:** Rails\
**Created:** [November 29, 2007, 12:25pm UTC](https://www.ruby-forum.com/t/ruby-newbie-help-regarding-strings/121624 "2007-11-29T12:25:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jagan](https://www.ruby-forum.com/u/jagan)\
**Post date:** [November 29, 2007, 12:25pm UTC](https://www.ruby-forum.com/t/ruby-newbie-help-regarding-strings/121624/1 "2007-11-29T12:25:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jagan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jagan](https://www.ruby-forum.com/u/jagan)\
**Post date:** [November 29, 2007, 12:36pm UTC](https://www.ruby-forum.com/t/ruby-newbie-help-regarding-strings/121624/2 "2007-11-29T12:36:17Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![jagan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jagan](https://www.ruby-forum.com/u/jagan)\
**Post date:** [November 29, 2007, 12:39pm UTC](https://www.ruby-forum.com/t/ruby-newbie-help-regarding-strings/121624/3 "2007-11-29T12:39:40Z")

</div>

On Nov 29, 2007, at 3:24 AM, Jagan wrote:

> how can i achieve this

use .downcase

[http://www.ruby-doc.org/docs/ProgrammingRuby/html/](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

---

<div class="post-metadata">

**Author:** ![jagan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jagan](https://www.ruby-forum.com/u/jagan)\
**Post date:** [November 29, 2007, 12:59pm UTC](https://www.ruby-forum.com/t/ruby-newbie-help-regarding-strings/121624/4 "2007-11-29T12:59:00Z")

</div>

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.
