Prev / Next

2003-09-29 / 2つの文字列の先頭から等しい文字列を抜き出す

Linuxビボ〜ろく
- 09-26 http://ponx.s5.xrea.com/bibo/20030926.html#p03
- 09-28 http://ponx.s5.xrea.com/bibo/20030928.html#p01
- 09-29 http://ponx.s5.xrea.com/bibo/20030929.html#p01
より.

def match_first(a,b)
  i = 0
  while a[i] and b[i] and a[i] == b[i]
    i+=1
  end
  a[0, i]
end


def match_first(a,b)
  a.size.times{|i|
    return(a[0,i]) if a[i] != b[i]
  } and a
end


comments powered by Disqus