Dmitry Buzdin
11/17/2006 2:28:00 PM
Check the manual
str[0] will return a numeric representation of the character
what You need is str[0,1] one character starting from the first
position.
Try this:
class String
def variantes
@variantes = 0
Range.new(0, 14).each { |i|
if (self[i,1] == "2" || self[i,1] == "X")
@variantes = @variantes + 1
end
}
return @variantes
end
end
str = "XXXXX22222XXXXX"
puts str.variantes
Dmitry