3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rubyのdeleteメソッドで複数の文字列を削除

Posted at

deleteメソッドについて

最近paizaで勉強中なので、メモ用に残します。

deleteメソッド

deleteメソッド、delete!メソッドは文字列から、指定の文字列を削除するメソッド。

使用例

str = 'abcde'
puts str.delete('a') # bcde
puts str.delete('abc') # de

みたいな感じですね。。
そんなの言われなくてもわかってるよ!という方がほとんどですね

しかし、一つの文字列から複数の文字を削除したい時はどうでしょうか

str = 'abcde'
puts str.delete('a' 'c') # bde

こうします。
カンマがいらないんですね〜
なんでなのかはわかりませんが..笑

もし知ってる方がいれば教えてください!

以上

3
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?