Project

General

Profile

Actions

Backport #3747

closed

Possible bug of String#count?

Added by lirh (Ruohao Li) over 13 years ago. Updated almost 13 years ago.

Status:
Closed
[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

Actions #1

Updated by darix (Marcus Rückert) over 13 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

Actions #2

Updated by lirh (Ruohao Li) over 13 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

Actions #3

Updated by shyouhei (Shyouhei Urabe) over 13 years ago

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

=begin

=end

Actions #4

Updated by naruse (Yui NARUSE) over 13 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

Actions #5

Updated by naruse (Yui NARUSE) over 13 years ago

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

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0