Tuesday, October 10, 2006

Rails Multibyte Support

Changeset 5223 เพิ่ม feature ในการ support multibyte
ลองดูตัวอย่าง

>> $KCODE='UTF8'
=> "UTF8"
>> name = 'ภาษาไทย'
=> "ภาษาไทย"

>> name.length
=> 21
>> name.chars.length
=> 7

>> name.reverse
=> "\242\270룠蒹ಸ੸ಸ࠸\340"
>> name.chars.reverse
=> #<ActiveSupport::Multibyte::Chars:0x28ad624 @string="ยทไาษาภ">
>> name.chars.reverse.to_s
=> "ยทไาษาภ"

>> name[1..3]
=> "\270\240\340"
>> name[0..3]
=> "ภ\340"
>> name.chars[0..3].to_s
=> "ภาษา"

Related link from Roti

1 comment:

bact' said...

ต่อไปห้ามลืม .chars :)