Mega Code Archive

 
Categories / Ruby / String
 

Use each_char with multibyte chars

s = "¥1000" s.each_char {|x| print "#{x} " }         # Prints "¥ 1 0 0 0". Ruby 1.9 0.upto(s.size-1) {|i| print "#{s[i]} "}  # Inefficient with multibyte chars