文字列操作の比較表:Ruby, VimScript

Vim 7.2 対応


http://0xcc.net/blog/archives/000137.html
だいぶ適当。間違いなどがあったらご指摘いただけると助かります。

Ruby (String) VimScript(string)
s = "abc" let s = "abc"
s = x + y let s = x . y
s == x s ==# x
s % [x, y]
sprintf(s, x, y) printf(s, x, y)
[x, y, z].join(s) call join([x, y, z], s)
s.capitalize call substitute(s, '\w\+', '\u\0', "")

s.capitalize!
s.center(x) :center ならある
s.chomp
s.chomp!
s.chop let s = strpart(s, 0, strlen(s)-1)
s.chop!
s.clear let s = ""
s.concat(x) let s .= x
s.count(x)
s.crypt(x) rot13 なら g? でできる
s.delete!(x) let s = substitute(s, x, "", "g")
s.downcase tolower(s)
s.downcase!
s.each_byte {|x| ... } let i = 0

let len = strlen(s)

while i < len

  let x = strpart(s, i, 1)

  ...

  let i = i + 1

endwhile
s.each_line {|x| ... } let a = split(s, '\n')

for x in a

  ...

endfor

s.empty? s == ""
s.end_with(x)*4 s =~# x . "$"
s.gsub(x, y) call substitute(s, x, y, "g")
s.gsub!(x, y)
s.hex str2nr(s, 16)
s.to_i(16) str2nr(s, 16)
s.include?(x) s =~ x
s.index(x) call stridx(s, x)
s.insert(i, x)
s.length strlen(s)
s.size
s.ljust(x) :left ならある
s.lstrip call substitute(s, '^\s\+', '', '')
s.lstrip!
s.match(x) s =~# x
x.match(s)
s.next!
s.succ!
s.oct str2nr(s, 8)
s.to_i(8) str2nr(s, 8)
s.partition(x)*4
replace(x)
s.reverse
s.reverse!
s.rindex(x) strridx(s, x)
s.rjust(x) :right ならある
s.rpartition(x)*4
s.rstrip call substitute(s, '\s\+$', '', '')
s.rstrip!
s.scan(x) { ... }
s[i] s[i]
s.slice(i) strpart(s, i, 1)
s[i..-1] strpart(s, i)
s.slice(i..-1)
s[i, l] strpart(s, i, l)
s.slice(i, l)
s[i..j] strpart(s, i, j-i+1)
s.slice(i..j)
s[i...j] strpart(s, i, j-i)
s.slice(i...j)
s.split(x) call split(s, x)
s.start_with(x)*4 s =~# "^" . x
s.strip call substitute(s, '\(^\s\+\)\|\(\s\+$\)', '', 'g')
s.strip!
s.sub(x, y) call substitute(s, x, y, '')
s.sub!(x, y)
s.swapcase ~ ならある
s.to_f
s.to_i s
s.tr!(x, y)
s.tr_s!(x, y)
s.unpack(x)
s.upcase toupper(s)
s.upcase!
Regexp.escape(s)
Regexp.quote(s)