ruby->clojure.contrib.str-utils
rubyでやってみると、こんな感じ><
re-split
文字列のパターンによる分割
"a, b, c, d, e, f, ".split ' ' #=>["a,", "b,", "c,", "d,", "e,", "f,"] "a, b, c, d, e, f, ".split ',' #=>["a", " b", " c", " d", " e", " f", " "] "1,2,3,4,5".split("," , 1) #=>["1,2,3,4,5"] "1,2,3,4,5".split("," , 2) #=>["1", "2,3,4,5"] "1,2,3,4,5".split("," , 5) #=>["1", "2", "3", "4", "5"] "1,2,3,4,5".split("," , 6) #=>["1", "2", "3", "4", "5"]
re-partition
文字列のパターンによる部分文字列への分離
instance method String#partition (Ruby 1.8.7)
"abc123def".partition /\d+/ #=>["abc", "123", "def"] #"abc123def".split /\d+/ #=>["abc", "def"] "abc123def".partition /[a-z]+/ #=>["", "abc", "123def"] #<=clojureと結果が違うw;
re-gsub,re-sub
文字列のパターンによる(一部)交換
"rubyonrails".gsub(/r/,"R") #=>"RubyonRails" "rubyonrails".sub(/r/,"R") #=>"Rubyonrails"
str-join
%w[Perl Python Ruby].join " , " #=>"Perl , Python , Ruby"
chop,chomp
"abc".chop #=>"ab" "abc\n".chop #=>"abc" "abc".chomp #=>"abc" "abc\n".chomp #=>"abc"
String#partition以外は、だいたい似たような動作です。
str-utils作った人かなりのRuby好きだ(`Д´)9m