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 on rails “如何替换”;插入空格或删除第一个和最后一个符号?_Ruby On Rails_String_Character - Fatal编程技术网

Ruby on rails “如何替换”;插入空格或删除第一个和最后一个符号?

Ruby on rails “如何替换”;插入空格或删除第一个和最后一个符号?,ruby-on-rails,string,character,Ruby On Rails,String,Character,我获取xml数据,并从中获得价值。 我需要删除符号[和] 这是我的代码,它给出了关于未设计变量的错误: @xml = XmlSimple.xml_in(res.content)//here I get xml document payKey = @xml["payKey"]//gere I get needed value //it looks like "[some character]" so I need to delete [ and

我获取xml数据,并从中获得价值。 我需要删除符号[和] 这是我的代码,它给出了关于未设计变量的错误:

         @xml = XmlSimple.xml_in(res.content)//here I get xml document
         payKey = @xml["payKey"]//gere I get needed value
         //it looks like "[some character]" so I need to delete [ and ]
         //I tried
         payKey = @xml["payKey"].to_s()//to use tr method
         payKey = payKey.tr("[]", "")//replacing
        redirect_to "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay?cmd=_ap-payment&paykey=#{paykey}"//inserting into url
结果:

            svcs.sandbox.paypal.com/AdaptivePayments/Pay?cmd=_ap-payment&paykey="AP-7NK73769LH704515X"
所以我需要删除“标志。有人能帮我吗?

我愚蠢的回答。”

  payKey = payKey[1..20]