# Submitting search term in quotation marks

**URL:** <https://www.ruby-forum.com/t/submitting-search-term-in-quotation-marks/184398>\
**Category:** Ruby\
**Created:** [March 1, 2010, 11:10pm UTC](https://www.ruby-forum.com/t/submitting-search-term-in-quotation-marks/184398 "2010-03-01T23:10:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roger99999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@roger99999](https://www.ruby-forum.com/u/roger99999)\
**Post date:** [March 1, 2010, 11:10pm UTC](https://www.ruby-forum.com/t/submitting-search-term-in-quotation-marks/184398/1 "2010-03-01T23:10:40Z")

</div>

Silly question but I can’t seem to find the answer online. I’m  
submitting a search phrase in a scraper and I would like that to be in  
quotation marks. Because the sterm="\*\*\*\*" is already in quotation  
marks in the code as:

sterm = “United States”

, I would have to do “”\*\*\*\*\*\*"" and that generates an error. How does  
one do this?  
many thanks in advance and apologies for posting such basic questions!  
Roger

The error I’m getting is the following.

$ ruby article\_parse\_27feb2010.rb  
article\_parse\_27feb2010.rb:53: syntax error, unexpected tCONSTANT,  
expecting $end  
sterm = " “Double Espresso with Whipped Cream” "

---

<div class="post-metadata">

**Author:** ![roger99999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@roger99999](https://www.ruby-forum.com/u/roger99999)\
**Post date:** [March 1, 2010, 11:31pm UTC](https://www.ruby-forum.com/t/submitting-search-term-in-quotation-marks/184398/2 "2010-03-01T23:31:45Z")

</div>

On Mon, Mar 1, 2010 at 11:10 PM, roger99999 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> many thanks in advance and apologies for posting such basic questions!  
> Roger
> 
> The error I’m getting is the following.
> 
> $ ruby article\_parse\_27feb2010.rb  
> article\_parse\_27feb2010.rb:53: syntax error, unexpected tCONSTANT,  
> expecting $end  
> sterm = " “Double Espresso with Whipped Cream” "

‘“Double Espresso with Whipped Cream”’  
%q{“Double Espresso with Whipped Cream”}

Jesus.

---

<div class="post-metadata">

**Author:** ![roger99999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@roger99999](https://www.ruby-forum.com/u/roger99999)\
**Post date:** [March 1, 2010, 11:44pm UTC](https://www.ruby-forum.com/t/submitting-search-term-in-quotation-marks/184398/3 "2010-03-01T23:44:02Z")

</div>

On Mon, Mar 1, 2010 at 4:10 PM, roger99999 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> many thanks in advance and apologies for posting such basic questions!  
> Roger
> 
> The error I’m getting is the following.
> 
> $ ruby article\_parse\_27feb2010.rb  
> article\_parse\_27feb2010.rb:53: syntax error, unexpected tCONSTANT,  
> expecting $end  
> sterm = " “Double Espresso with Whipped Cream” "

There are a few ways you can do it. If your string has double quotes  
around it, you escape the embedded double quotes with a backslash,  
thus “"United States"”.

Or you can enclose your string in single quotes and use the double  
quotes as-is (but not that this will not allow you to use #{…} or #$  
or #@ inside the string).

Finally, you can do as Jesus said, and use %q followed by the string  
enclosed in some delimiters like { }, ( ), [], etc.; you can actually  
even use single non-alphanumeric delimiters like | |, as long as they  
match (and aren’t used inside the string itself).

---

<div class="post-metadata">

**Author:** ![roger99999](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@roger99999](https://www.ruby-forum.com/u/roger99999)\
**Post date:** [March 2, 2010, 2:56am UTC](https://www.ruby-forum.com/t/submitting-search-term-in-quotation-marks/184398/4 "2010-03-02T02:56:36Z")

</div>

On Mar 1, 2:43 pm, Eric C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > many thanks in advance and apologies for posting such basic questions!  
> > around it, you escape the embedded double quotes with a backslash,  
> > thus “"United States"”.
> 
> Or you can enclose your string in single quotes and use the double  
> quotes as-is (but not that this will not allow you to use #{…} or #$  
> or #@ inside the string).
> 
> Finally, you can do as Jesus said, and use %q followed by the string  
> enclosed in some delimiters like { }, ( ), [], etc.; you can actually  
> even use single non-alphanumeric delimiters like | |, as long as they  
> match (and aren’t used inside the string itself).

Jesus and Eric,

Perfect - my problem is solved. Many thanks again.

Roger
