First letter of UTF-8 string?

How to get first letter of UTF-8 string?

I try with :
item.name.slice(0…0) – works ok when first letter is regular ascii
character, don’t works for local Croatian characters: “©ÐÈÆ®¹ðèæ¾”

item.name.slice(0…1) – this works ok for items starting with Croatian
character but returns two letters for other items

Is there slice version (or something like that) which works with
characters not bytes.

Thanks,
Igor.

Hi !

2005/11/9, Igor A. [email protected]:

Is there slice version (or something like that) which works with
characters not bytes.

Unfortunately, Ruby String objects always work with bytes, not
characters. You will have to look into the Unicode Gem.
Unfortunately, it requires some kind of local extension to be
installed. I have never worked with it myself.

Bye,
François

Igor A. wrote:

How to get first letter of UTF-8 string?

$KCODE = ‘u’
string.match(/^./).to_s