https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112014-11-16T12:18:10ZRuby Issue Tracking SystemRuby master - Bug #10518: String "delete" method does not remove some characters from input stringhttps://bugs.ruby-lang.org/issues/10518?journal_id=499782014-11-16T12:18:10ZHanmac (Hans Mackowiak)hanmac@gmx.de
<ul></ul><p>need to escape the -<br>
irb(main):001:0> str = 'A-B'<br>
=> "A-B"<br>
irb(main):002:0> str.delete ' \-#'<br>
=> "AB"</p>
<p>because with ' -#' i think you cant to remove from " " to "#"</p> Ruby master - Bug #10518: String "delete" method does not remove some characters from input stringhttps://bugs.ruby-lang.org/issues/10518?journal_id=499792014-11-16T12:18:24Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p><a href="mailto:sergio.gallelli@gmail.com" class="email">sergio.gallelli@gmail.com</a> wrote:</p>
<blockquote>
<p>irb(main):001:0> str = 'A-B'<br>
=> "A-B"<br>
irb(main):002:0> str.delete ' -#'<br>
=> "A-B"</p>
</blockquote>
<p>' -#' is interpreted as: range of characters from ' ' (space) to '#'.<br>
See String#count documentation</p>
<p>I suppose it is weird and surprising behavior, but I doubt it can change<br>
for compatibility. I would normally use String#tr if I wanted a range.</p> Ruby master - Bug #10518: String "delete" method does not remove some characters from input stringhttps://bugs.ruby-lang.org/issues/10518?journal_id=499802014-11-16T12:20:42Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I looked at the String#count documentation:</p>
<p><a href="http://www.ruby-doc.org/core-2.1.4/String.html#method-i-count" class="external">http://www.ruby-doc.org/core-2.1.4/String.html#method-i-count</a></p>
<p>Allow me to copy paste from it:</p>
<p>"Each other_str parameter defines a set of characters to count. The intersection of these sets defines the characters to count in str. Any other_str that starts with a caret ^ is negated. The sequence c1-c2 means all characters between c1 and c2. The backslash character can be used to escape <code>^ or - and is otherwise ignored unless it appears at the end of a sequence or the end of a other_str."</code></p>
<p>Firstly, why are the strange code tags there?</p>
<p>Secondly - this is not made very clear to me IMHO that the - character is treated in a special way.</p>
<p>Perhaps the documentation can be made more clear in this regard.</p> Ruby master - Bug #10518: String "delete" method does not remove some characters from input stringhttps://bugs.ruby-lang.org/issues/10518?journal_id=499812014-11-16T12:21:42Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>Aha, the code tags do not appear here on bugs.ruby-lang.org, but if you click on the<br>
link above at:</p>
<p><a href="http://www.ruby-doc.org/core-2.1.4/String.html#method-i-count" class="external">http://www.ruby-doc.org/core-2.1.4/String.html#method-i-count</a></p>
<p>then you can see them.</p> Ruby master - Bug #10518: String "delete" method does not remove some characters from input stringhttps://bugs.ruby-lang.org/issues/10518?journal_id=499832014-11-16T12:39:04Zsergio.gallelli (Sergio Gallelli)sergio.gallelli@gmail.com
<ul></ul><p>Sorry, I did not realize the dash character stays for range and, as such, must be escaped.<br>
This is probably convenient in some cases, however it might be "dangerous" in other circumstances.<br>
Anyway, this is the way Ruby works, so I think this call can be closed.<br>
Thanks.</p> Ruby master - Bug #10518: String "delete" method does not remove some characters from input stringhttps://bugs.ruby-lang.org/issues/10518?journal_id=514212015-02-06T02:39:41Zshugo (Shugo Maeda)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul> Ruby master - Bug #10518: String "delete" method does not remove some characters from input stringhttps://bugs.ruby-lang.org/issues/10518?journal_id=514232015-02-06T02:51:40Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Status</strong> changed from <i>Closed</i> to <i>Rejected</i></li></ul>