Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a string to a list in Io?

For example, I'd like to turn "hello" into list(104, 101, 108, 108, 111) or list("h", "e", "l", "l", "o")

So far I've created an empty list, used foreach and appended every item to the list myself, but that's not really a concise way to do it.

like image 889
Jakob Avatar asked Nov 23 '10 10:11

Jakob


2 Answers

My own suggestion:

Sequence asList := method(
  result := list()
  self foreach(x,
    result append(x)
  )
)

Haven't tested it performance-wise but avoiding the regexp should account for something.

like image 137
Jakob Avatar answered Sep 27 '22 20:09

Jakob


Another nicely concise but still unfortunately slower than the foreach solution is:

Sequence asList := method (
    Range 0 to(self size - 1) map (v, self at(v) asCharacter)
)
like image 32
draegtun Avatar answered Sep 27 '22 20:09

draegtun