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 1/17/07, 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 ?

Well, mostly you don't need to do this. In fact, more often, when doing
typical web sites, reporting, and data processing, I need to get the
number of character positions a string will take up in a fixed-width
font; I'd be interested in seeing how well Python does with that.

However, to answer your question:

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

am I missing somthing - doesn't this just count  all the ascii chars in  your string ?




Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links