ลองดูตัวอย่าง
>> $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
=> "ภาษา"
1 comment:
ต่อไปห้ามลืม .chars :)
Post a Comment