Skip to content

Instantly share code, notes, and snippets.

@toby55kij
Created October 11, 2010 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toby55kij/619851 to your computer and use it in GitHub Desktop.
Save toby55kij/619851 to your computer and use it in GitHub Desktop.
// g100pon #58 StringクラスのGDKメソッド
// 1.7.3で追加されたメソッド
// capitalize:先頭文字を大文字化
assert 'foo'.capitalize() == 'Foo'
// expand:タブを空白に展開
assert '¥tabc'.expand() == ' abc' //引数無しの場合タブは8
assert '¥tdef¥tghi'.expand(4) == ' def ghi'
// stripIndent:各行の先頭にある共通な空白を除去
assert ' abc abc¥n def¥n ¥n ghi'.stripIndent() == 'abc abc¥n def¥n¥n ghi'
// stripMargin:各行の先頭に当たる文字が現れるまで空白・コントロール文字を除去
assert '''¥t|foo
|bar
|hoge'''.stripMargin() == 'foo¥nbar¥nhoge' //引数無しの場合先頭文字は|
assert '''abc
/def'''.stripMargin('/') == 'abc¥ndef'
// tr:指定された文字列セットを別の文字列セットに変換
assert 'hello, world.'.tr('a-z', 'A-Z') == 'HELLO, WORLD.'
// unexpand:連続した空白をタブに変換
assert ' abc'.unexpand() == '¥tabc' //引数無しの場合空白8つをタブに
assert ' def ghi'.unexpand(2) == '¥tdef¥t ghi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment