Module: Ferret::Utils::StringHelper
- Defined in:
- lib/ferret/utils/string_helper.rb,
ext/string_helper.c
Defined Under Namespace
Classes: StringReader
Class Method Summary collapse
-
.string_difference(s1, s2) ⇒ Object
Compares two strings, character by character, and returns the first position where the two strings differ from one another.
Instance Method Summary collapse
Class Method Details
.string_difference(s1, s2) ⇒ Object
Compares two strings, character by character, and returns the first position where the two strings differ from one another. eg.
string_difference('dustbin', 'dusty') # => 4
string_difference('dustbin', 'evening') # => 0
string_difference('eve', 'evening') # => 3
- s1
-
The first string to compare
- s2
-
The second string to compare
- returns
-
The first position where the two strings differ.
39 40 41 42 43 44 45 |
# File 'lib/ferret/utils/string_helper.rb', line 39 def StringHelper.string_difference(s1, s2) len = [s1.length, s2.length].min len.times do |i| return i if (s1[i] != s2[i]) end return len end |
Instance Method Details
#string_difference(rstr1, rstr2) ⇒ Object
22 23 24 25 26 |
# File 'ext/string_helper.c', line 22
static VALUE
frt_sh_string_difference(VALUE self, VALUE rstr1, VALUE rstr2)
{
return INT2FIX(frt_sh_string_difference_int(self, rstr1, rstr2));
}
|