Check string size for non ascii code : KCODE « Development « Ruby






Check string size for non ascii code



#!/usr/bin/ruby -Ku -rjcode

string = "\xef\xbc\xa1" + "\xef\xbc\xa2" + "\xef\xbc\xa3" +
         "\xef\xbc\xa4" + "\xef\xbc\xa5" + "\xef\xbc\xa6"

string.size                                            # => 18
string.jsize                                           # => 6

 








Related examples in the same category

1.Setting the $KCODE global variable to 'u' and loading jcode gives regular expressions awareness of UTF-8 characters
2.Using jcode you can make regular expressions UTF-8 aware
3.$KCODE Demo
4.$KCODE = 'u'
5.Handling International Encodings
6.Count non-ascii string
7.Length of non-ascii string