Robin Stocker
7/8/2006 7:24:00 PM
Marcin MielżyÅ?ski wrote:
> String#index should be the fastest
I'm afraid it isn't suitable for this case. String#index searches the
whole string when the string doesn't start with the start, which is very
bad.
Use String#[] or a regular expression:
text = "this is a test"
search = "this"
text[0, search.length] == search #=> true
text =~ /^this/ #=> 0 (true)
text =~ /^test/ #=> nil (false)
Cheers,
Robin Stocker