[pharo 2.0] IP address to ByteArray

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[pharo 2.0] IP address to ByteArray

vonbecmann

Hi all,
    Is there a better way to convert an IP address to a ByteArray?
    I'm doing this
   
     ('127.0.23.11' subStrings: '.') collect: [:each | each asInteger ] as: ByteArray 

thanks

--
Bernardo E.C.
Reply | Threaded
Open this post in threaded view
|

Re: [pharo 2.0] IP address to ByteArray

Stéphane Ducasse
The problem is that

'127.0.23.11' copyUpTo: $.

copyUpTo: does not help because what you would like is a method that return
        '127' and '0.23.11'

I could not find one. If you do or define it I would like to add it to the system.
Because with it we could do one pass instead of two.

Stef

On Jul 31, 2012, at 7:21 PM, Bernardo Ezequiel Contreras wrote:

>
> Hi all,
>     Is there a better way to convert an IP address to a ByteArray?
>     I'm doing this
>    
>      ('127.0.23.11' subStrings: '.') collect: [:each | each asInteger ] as: ByteArray
>
> thanks
>
> --
> Bernardo E.C.


Reply | Threaded
Open this post in threaded view
|

Re: [pharo 2.0] IP address to ByteArray

vonbecmann

    ('.' split: '127.0.23.11') collect: [:each | each asInteger ] as: ByteArray 

I'll prefer this one, I think it's more legible

thanks

On Tue, Jul 31, 2012 at 4:21 PM, Stéphane Ducasse <[hidden email]> wrote:
The problem is that

'127.0.23.11' copyUpTo: $.

copyUpTo: does not help because what you would like is a method that return
        '127' and '0.23.11'

I could not find one. If you do or define it I would like to add it to the system.
Because with it we could do one pass instead of two.

Stef

On Jul 31, 2012, at 7:21 PM, Bernardo Ezequiel Contreras wrote:

>
> Hi all,
>     Is there a better way to convert an IP address to a ByteArray?
>     I'm doing this
>
>      ('127.0.23.11' subStrings: '.') collect: [:each | each asInteger ] as: ByteArray
>
> thanks
>
> --
> Bernardo E.C.





--
Bernardo E.C.