Ruby 1.8.7 Reference Manual > All Libraries > Builtin Library > class String > bytesize

instance method String#bytesize

bytesize -> Integer

文字列のバイト長を整数で返します。

例:

#coding:UTF-8
# 実行結果は文字コードによって異なります。
p "いろは".size     #=> 6
p "いろは".bytesize #=> 9

[SEE_ALSO] String#size