From: Ruohao Li Date: 2010-08-20T00:56:18+09:00 Subject: Re: Is this a bug of String#count? Roger Pack wrote: >>>> s = "a\u4e00" > >>>> s.count("^a") >> => 0 >> >> Why the above result is 0 not 1? After all there are 2 characters >> in the string s. Is this a bug of String#count? > > count returns the sum of occurrences of characters. I don't see any ^a > in the original string... But according to the documentation, "Any _other_str_ that starts with a caret (^) is negated", thus the following behavior: $ irb --simple-prompt >> s = "abc" => "abc" >> s.count("^a") => 2 There are two characters in s that is *not* "a". -- Posted via http://www.ruby-forum.com/.