# String to String?

**URL:** <https://www.ruby-forum.com/t/string-to-string/181527>\
**Category:** Rails\
**Created:** [January 13, 2010, 8:12am UTC](https://www.ruby-forum.com/t/string-to-string/181527 "2010-01-13T08:12:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 13, 2010, 8:12am UTC](https://www.ruby-forum.com/t/string-to-string/181527/1 "2010-01-13T08:12:55Z")

</div>

Really basic question.

How can I convert “this” to ‘this’

convert from a double quotes string to a single quotes string.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 13, 2010, 8:18am UTC](https://www.ruby-forum.com/t/string-to-string/181527/2 "2010-01-13T08:18:46Z")

</div>

On Tue, Jan 12, 2010 at 11:11 PM, removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> Really basic question.
> 
> How can I convert “this” to ‘this’
> 
> convert from a double quotes string to a single quotes string.

For what purpose?

-Conrad

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 13, 2010, 9:17am UTC](https://www.ruby-forum.com/t/string-to-string/181527/3 "2010-01-13T09:17:17Z")

</div>

u can try this

@re = “this”.gsub(“this”,"‘this’")  
puts @re  
Thanks  
seenu

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 13, 2010, 9:19am UTC](https://www.ruby-forum.com/t/string-to-string/181527/4 "2010-01-13T09:19:03Z")

</div>

I could be misreading, but I thought it was a simple question of how to  
change double quotes to single quotes.

try  
var = ‘“this”’  
var.gsub!(’"’,"’")

Cheers  
Simon

On Wed, 13 Jan 2010 16:14:47 +0800, srinivasan sakthivel

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 13, 2010, 11:57am UTC](https://www.ruby-forum.com/t/string-to-string/181527/5 "2010-01-13T11:57:39Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Really basic question.
> 
> How can I convert “this” to ‘this’
> 
> convert from a double quotes string to a single quotes string.

Try this one :-  
str = ‘“hai”’  
puts str  
puts str.sub(/^"(.\*)"$/, ‘’\1’’)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 13, 2010, 4:14pm UTC](https://www.ruby-forum.com/t/string-to-string/181527/6 "2010-01-13T16:14:03Z")

</div>

Thanks guys, was having some issues creating headings based on an  
array of column names from the DB acquired using User.column\_name  
where “User” is the table. Turns out my problem was unrelated in the  
link\_to code…should have went to bed sooner.
