2003-09-29 Mon

[別の年の同じ日: 2002 2004 2005 2006 2007 2008 2009 2010 2011 2012

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