如何更换"进入太空或删除第一个和最后一个符号?

时间:2012-07-18 17:58:44

标签: 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 ]
         //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"

所以我需要删除“迹象。有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我的愚蠢回答

  payKey = payKey[1..20]