reply inline. . . Dan Schmidt wrote: > > "Jiangyi Liu" <jyliu / 163.net> writes: > > | I met a problem when I tried to write some Ruby code to learn > | Ruby. The following code just can't work as expected, > | > | "Hello".each_byte { |c| > | if c == "o" > | print "oh, i got an o!", "\n" > | end > | } > > In ruby, characters and one-element strings are different types, > unlike some other languages. each_byte is returning exactly that. . . the number associate with each byte. As far as I can tell, Ruby doesn't have a "Character" object. You typically (conveniently) use one-character strings. > > Try 'if c == ?o' insead. I don't think that will work. 'o' is a string just like "o" Try this instead [it "splits" the string into an array of strings (each one character long) and iterates over them]. "hello".split(//).each{|c| if (c == "o") then puts "oh, I got an o" end } or more concisely: "hello".split(//).each{|c| puts "oh, I got an o" if (c == "o")} enjoy Ruby, I do, /<