Count bytes : each byte « File Directory « Ruby





Count bytes


file = File.new("myfile")
e_count = 0
file.each_byte do |byte|
  e_count += 1 if byte == ?e
end

 

Related examples in the same category

1.read an I/O stream byte by byte with each_byte:
2.each_byte is always associated with a block.