Mega Code Archive

 
Categories / Ruby / Development
 

Count non-ascii string

string = "\xef\xbc\xa1" + "\xef\xbc\xa2" + "\xef\xbc\xa3" +          "\xef\xbc\xa4" + "\xef\xbc\xa5" + "\xef\xbc\xa6" string.count "\xef\xbc\xa2"                            # => 13 string.jcount "\xef\xbc\xa2"                           # => 1