From: Dan Schmidt Date: 2000-12-22T05:10:02+09:00 Subject: [ruby-talk:7908] Re: Comparsion Problem? Keith Weinberg writes: | Dan Schmidt wrote: | > | > "Jiangyi Liu" 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. Right, characters are bytes. | You typically (conveniently) use one-character strings. Sometimes it is more convenient to treat characters as one-character strings; sometimes it is more convenient to treat them as bytes. | > Try 'if c == ?o' insead. | | I don't think that will work. 'o' is a string just like "o" I tried it before I posted it, and it did work. Does it not work for you? "o" is a string. 'o' is a string. ?o is a character. -- http://www.dfan.org