Re: reverse String asHex

"Mildred Ki'Lya" <[email protected]> Fri, 9 Dec 2011 09:45:16 +0100
Newsgroups gmane.comp.lang.io
Message-ID <CAHU8KxjtjG6YPTFKbU4kir9ZVjz9V=aLdstJgHDJMvJyarLDfw@mail.gmail.com>
On 8 December 2011 19:56, Steve Dekorte <[email protected]> wrote:

> **
>
>
>
> On 2011-12-08 Thu, at 06:43 AM, Mildred Ki'Lya wrote:
>
> In particular I would prefer having String asNumber(base) instead of
> having to do a concatenation.
>
>
> IIRC, aSequence fromBase(16) should work.
>

Thank you.

I now have:

Sequence fromHex := method(
  res := Sequence clone;
  for(i, 1, self size, 2,
    res append(self exSlice(i-1, i+1) fromBase(16))
  );
  res
)

Now, if you have any idea on how to get rid of the for loop and use
something as the map method. The problem is that I need to get the
characters in the sequence two by two.

Say for example I have "6162636465"
If I could get in an operation list("61", "62", "63", "64", "65")
I could convert it easily to list("a", "b", "c", "d", "e") and then to
"abcde"

I can do that with regexp, but I would prefer to use a lighter solution:

io> "6162636465" allMatchesOfRegex("..") map(at(0) fromBase(16)
asCharacter) join
==> abcde

Sequence fromHex := method(
  self allMatchesOfRegex("..") map(at(0) fromBase(16) asCharacter) join
)

In Ruby, there is Enumerable.each_slice that does this job.
Do we have something like that in Io, if not, could we have it?

Mildred

-- 
Mildred Ki'Lya
http://mildred.fr