Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Learn a Variety of Languages . . . . . . . (was: Re: [tlug] Re: Bourne Shell is the most appropriate scripting language)



On Wed, 17 Jan 2007 17:08:03 +0900, Curt Sampson <cjs@example.com> wrote:

On Wed, 17 Jan 2007, Ian MacLean wrote:

really ? - so how do you *easily* get a character count for a string of
utf-8 bytes ?

<Snip>

However, to answer your question:

     class String
 	def utf8_char_count
 	    split('').select { |c| c[0] < 128 }.length
 	end
     end

Now, for the rest of your program, you can just say String.utf8_char_count.

I think you can require 'jcode' and the just use jlength/jsize on each string Such as : "foo".jsize

It recognizes UTF8, EUC and ShiftJis

Zev


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links