Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby中带字符串的Concat双引号_Ruby_String_Concat - Fatal编程技术网

Ruby中带字符串的Concat双引号

Ruby中带字符串的Concat双引号,ruby,string,concat,Ruby,String,Concat,我需要一个带双引号的字符串 尝试 expectedValue = "/""+expectedValue+"/"" 但没有起作用- 抛下错误- NoMethodError: undefined method `/' for "/+expectedValue+":String 请建议。您的意思可能是: expectedValue = "\""+expectedValue+"\"" 或更多红宝石风格: expectedValue = "\"#{expectedValue}\"" 您可以使用%Q

我需要一个带双引号的字符串

尝试

expectedValue = "/""+expectedValue+"/""
但没有起作用-

抛下错误-

NoMethodError: undefined method `/' for "/+expectedValue+":String
请建议。

您的意思可能是:

expectedValue = "\""+expectedValue+"\""
或更多红宝石风格:

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

您可以使用
%Q
,也可以简单地使用
%

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

expectedValue = %|"#{expectedValue}"|

如果你能接受一些答案,那也太好了。结束这个问题。