[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: adding anotehr each method to String

John Joyce

3/25/2007 8:01:00 AM

Might not do what you expect.
under current conditions you might get:
¨
u

instead of
ü


On Mar 25, 2007, at 4:25 PM, Une Bévue wrote:

> f it doesn't exist allready, i'd like to add another each method to
> String similar to each_byte except it loops over chars for example :
>
> "zero".each_char{|c| puts c}
>
> would print-out :
> z
> e
> r
> o
>
> i know how to add a new method to a given class, what i don't know is
> specifically for methods like each which pass an arg to a given
> block...
>
>
> --
> It's easy to play any musical instrument: all you have to do is
> touch the right key at the right time and the instrument will
> play itself. -- J.S. Bach
>


3 Answers

John Joyce

3/25/2007 8:41:00 AM

0

I mean you should check into the way Ruby works with multi-byte
characters!
But this should be watched carefully with every language.
Typing multibyte characters on many windows systems is a pain in the
behind. Luckily it's not so painful on osx, so I can type an umlaut
by option+u then the character I want it over.
Here is what happens...

irb(main):001:0> mystring ="\303\274mlaut"
=> "\303\274mlaut"
irb(main):002:0> puts mystring
ümlaut
=> nil
irb(main):003:0> puts mystring.length
7
=> nil


On Mar 25, 2007, at 5:25 PM, Une Bévue wrote:

> John Joyce <dangerwillrobinsondanger@gmail.com> wrote:
>
>> Might not do what you expect.
>> under current conditions you might get:
>> ¨
>> u
>>
>> instead of
>> ü
>
> then, u mean, it wouldn't work with NON-ASCII chars ?
>
> it doesn't matter in fact because i'm playing with US-ASCII chars only
> in that case.
>
> but thanks a lot, better to know !
> --
> It's easy to play any musical instrument: all you have to do is
> touch the right key at the right time and the instrument will
> play itself. -- J.S. Bach
>


unbewusst.sein

3/25/2007 9:23:00 AM

0

John Joyce <dangerwillrobinsondanger@gmail.com> wrote:

> Might not do what you expect.
> under current conditions you might get:
> ¨
> u
>
> instead of
> ü

then, u mean, it wouldn't work with NON-ASCII chars ?

it doesn't matter in fact because i'm playing with US-ASCII chars only
in that case.

but thanks a lot, better to know !
--
It's easy to play any musical instrument: all you have to do is
touch the right key at the right time and the instrument will
play itself. -- J.S. Bach

unbewusst.sein

3/25/2007 10:01:00 AM

0

John Joyce <dangerwillrobinsondanger@gmail.com> wrote:

> I mean you should check into the way Ruby works with multi-byte
> characters!

because i'm a french guy, i knew that )))

but, as writen, for such a tiny script I'll restrict to US-ASCII
converting :

grüß

to

gruess

if y would be a german guy )))

in french it's easier i'll convert all the :

éèêë to e und so weiter !

i'll have to check (as for the german ß) for ligatures too :

æ -> ae again und so weiter !

thanks !
> But this should be watched carefully with every language.
> Typing multibyte characters on many windows systems is a pain in the
> behind. Luckily it's not so painful on osx, so I can type an umlaut
> by option+u then the character I want it over.
> Here is what happens...
>
> irb(main):001:0> mystring ="\303\274mlaut"
> => "\303\274mlaut"
> irb(main):002:0> puts mystring
> ümlaut
> => nil
> irb(main):003:0> puts mystring.length
> 7
> => nil


--
It's easy to play any musical instrument: all you have to do is
touch the right key at the right time and the instrument will
play itself. -- J.S. Bach