Created
January 27, 2013 14:52
-
-
Save shyouhei/4648708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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