Project

General

Profile

Backport #3747

Possible bug of String#count?

Added by lirh (Ruohao Li) almost 9 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:31851]

Description

=begin
$ ruby -v
ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-darwin9]
$ cat c.rb
# -- coding: utf-8 --

s = "a\u3042" # \u3042 is the japanese hiragana "a"
puts s.encoding.name
puts s.count("a")
$ ruby c.rb
UTF-8
0

The result of count method should be 1 but is 0.
=end

History

#1

Updated by darix (Marcus Rückert) almost 9 years ago

=begin
didnt you want to say:
$ puts s.count("a")
1

if you do:
$ s = "a\u3042"
$ puts s.count("a")
1

=end

#2

Updated by lirh (Ruohao Li) almost 9 years ago

=begin
In the documentation of String#count, "Any other_str that starts with a
caret () is negated". Thus s.count("a") means the number of characters
that is not a, which should be 1.

=end

#3

Updated by shyouhei (Shyouhei Urabe) almost 9 years ago

  • Status changed from Open to Assigned
  • Assignee set to naruse (Yui NARUSE)

=begin

=end

#4

Updated by naruse (Yui NARUSE) almost 9 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r29146.
Ruohao, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

#5

Updated by naruse (Yui NARUSE) almost 9 years ago

  • Assignee changed from naruse (Yui NARUSE) to yugui (Yuki Sonoda)

=begin

=end

Also available in: Atom PDF