打印

[问题求助] 可否用数组多参数

可否用数组多参数

@strA="hello <0>"
arr=["no1","world"]

def show(arr)
 p @strA.sub(/<0>/,arr[1])          #输出效果 hello world
end

上面代码错了,帮忙修正!!!

TOP

可否用数组做参数

我想要的结果是输出:
本帖最近评分记录
  • liupei520520 R币 +5 鼓励提问我也想知道 2008-3-19 15:29

TOP

解决了



arr1 = Array.new
arr1[0]="msg001"
arr1[1]="cai1"
def showmsg( arr=[])
   p arr
 end
showmsg(arr1)


TOP

p @strA.sub("<0>","")+arr[1]
本帖最近评分记录
  • wscc111 R币 +2 我很赞同 2008-3-20 09:49

TOP

这里是一个通用的例子



class Msg
    def self.Message(arr=[])
      for i in 0..arr.length-2
         arr[0] = arr[0].sub(/<#{i}>/,arr[i+1])
      end
      str1=arr[0]
      return str1
    end
end


掉用:
arr1=["<0> not equal <1> or <2> not big than <3>","hello","hi","99","180"]
str = Msg.Message(arr1)
结果: str = "hello not equal hi or 99 not big than 180"

TOP

2008-11-23 23:04 Crawled by CCBot/1.0 (+http://www.commoncrawl.org/bot.html) @38.103.63.61