Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Oliver Haag www.ohcon.de

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

count characters

// description of your code here

class Counter
  
def initialize()
  @characters = Hash.new(0)
end

def read()
  @text = IO.read("text.txt")
end

def count_chars
  @text.each_byte do |ch|
  @characters[ch] +=1
  end
end

def report  
  @characters.each do |key, value|
    puts "#{key.chr} (#{key}) occurs #{value} times"
  end  
end

end

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed