简体   繁体   中英

Concat double quotes with String in Ruby

I need a string with double quotes

tried

expectedValue = "/""+expectedValue+"/""

but did not worked -

Throws below error -

NoMethodError: undefined method `/' for "/+expectedValue+":String

Please suggest.

Probably you mean:

expectedValue = "\""+expectedValue+"\""

or more in ruby style:

expectedValue = "\"#{expectedValue}\""

You can use %Q , or simply %

expectedValue = %Q{"#{expectedValue}"}

expectedValue = %|"#{expectedValue}"|

Reference: String literals

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM