Skip to content

Instantly share code, notes, and snippets.

@shyouhei
Created January 27, 2013 14:52
Show Gist options
  • Save shyouhei/4648708 to your computer and use it in GitHub Desktop.
Save shyouhei/4648708 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*- # Unicode UTF-8エンコーディングを指定する
# マルチバイトの乗算記号を含む文字列リテラル
s = "2×2=4"
# 文字列には5文字をエンコードする6バイトが含まれている
s.bytesize # => 6
s.bytesize.times {|i| print s.getbyte(i), " "} # "50 195 151 50 61 52"と表示
s.length # => 5
s.length.times {|i| print s[i], " "} # "2 × 2 = 4"と表示
s.setbyte(5, s.getbyte(5)+1) # sは"2×2=5"に
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment