Created
July 10, 2014 17:22
-
-
Save kyuden/9e3474d8fcf99caeee97 to your computer and use it in GitHub Desktop.
sliceの
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# []があるから範囲指定の文字列抽出用途では価値ない | |
"2012-08-01".slice(0..2) | |
"2012-08-01"[0..2] | |
# 正規表現で抽出文字列を絞り込めるはおおきな利点 | |
"2012-08-01".slice(/-(.+)-/) # => "-08-" | |
# ちなみにdeleteは削除後の文字列を返却するのが違い | |
"2012-08-01".delete(/-(.+)-/) # => "201201" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment