Hi -- On Tue, 6 Nov 2007, Jari Williamsson wrote: > What't the most elegant way to find a substring match at the very start of a > string? > > Currently I'm using this approach: > a = "long string" > key = "long" > if a[0, key.length] == key then > > ...while this might look ok, it doesn't look so good with constant strings: > if a[0, 4] == "long" then > or > if a[0, "long".length] == "long" then > > I guess what I'm looking for is something like: > if a.startswith("long") then > > Is there any such solution? You could do: if a.index("long") == 0 David -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Advancing With Rails, Edison, NJ, November 6-9 * Advancing With Rails, Berlin, Germany, November 19-22 * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details!