LoginSignup
1
1

More than 5 years have passed since last update.

末尾行を取り出す

Posted at

先頭行を取り出すにインスパイアされた。

string = "abc\ndef\nghi"
tail = string[/.*\Z/] # => "ghi"

string = "abc\ndef\nghi\n"
tail = string[/.*\Z/] # => "ghi"

string = "abc\ndef\n\n"
tail = string[/.*\Z/] # => ""

改行コードが \r\n の場合、 \r は取り出した文字列に残る。 String#strip すればよし。

1
1
0

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
1
1