# String Problems?

**URL:** <https://www.ruby-forum.com/t/string-problems/152880>\
**Category:** Ruby\
**Created:** [November 8, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/string-problems/152880 "2008-11-08T21:13:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jearb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@jearb](https://www.ruby-forum.com/u/jearb)\
**Post date:** [November 8, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/string-problems/152880/1 "2008-11-08T21:13:08Z")

</div>

There is probably an easy answer to this, but I need help. Recently I’ve  
started making a text-based adventure game in Ruby, and so far it’s  
going very well. One problem I’m having, though, is that whenever I use  
puts to output a string, the string is in quotes. Is there any way in  
which I can disable this?

Also, I can’t seem to get string literals to work. I’ll type in, for  
example,

p “You see a glass cup, and there is a door NORTH.\n There is also a  
long hallway SOUTH.”

And it will output the exact same - when I run the code, it says:  
“You see a glass cup, and there is a door NORTH.\n There is also a long  
hallway SOUTH.”

I have no idea how to fix said problems…can anyone help me?

Thanks,  
Jearb

---

<div class="post-metadata">

**Author:** ![jearb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@jearb](https://www.ruby-forum.com/u/jearb)\
**Post date:** [November 8, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/string-problems/152880/2 "2008-11-08T21:19:55Z")

</div>

Alle Saturday 08 November 2008, Carter Davis ha scritto:

> whenever I use  
> puts to output a string, the string is in quotes.  
> …  
> I’ll type in, for example,
> 
> p “You see a glass cup, and there is a door NORTH.\n There is also a  
> long hallway SOUTH.”

You aren’t using puts, you’re using p, which is a different thing. puts  
calls  
to\_s on its arguments, while p calls inspect. In the case of strings,  
to\_s  
gives a human-readable text, while inspect returns a version with all  
special  
characters escaped. For example:

s = “You see a glass cup, and there is a door NORTH.\n There is also a  
long hallway SOUTH.”  
s.to\_s

gives

You see a glass cup, and there is a door NORTH.  
There is also a long hallway SOUTH.

while

s.inspect

gives

“You see a glass cup, and there is a door NORTH.\n There is also along  
hallway  
SOUTH.”

which is want you get. Replace p with puts and it should work as you  
want.

I hope this helps

Stefano

---

<div class="post-metadata">

**Author:** ![jearb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@jearb](https://www.ruby-forum.com/u/jearb)\
**Post date:** [November 8, 2008, 9:26pm UTC](https://www.ruby-forum.com/t/string-problems/152880/3 "2008-11-08T21:26:57Z")

</div>

Carter Davis wrote:

> One problem I’m having, though, is that whenever I use  
> puts to output a string, the string is in quotes. Is there any way in  
> which I can disable this?  
> …  
> p “You see a glass cup, and there is a door NORTH.\n There is also a  
> long hallway SOUTH.”

It seems to me that the problem you’re having is that whenever you’re  
using  
_p_ you get the string in quotes (and with all control characters  
displayed  
in escaped form), which is what it’s supposed to do.  
If you do have the same problem with puts, please show the code using  
puts  
that exhibits this behaviour.

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![jearb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@jearb](https://www.ruby-forum.com/u/jearb)\
**Post date:** [November 8, 2008, 9:33pm UTC](https://www.ruby-forum.com/t/string-problems/152880/4 "2008-11-08T21:33:53Z")

</div>

Thank you so much! It works now. 😃
