如何在Io中将字符串转换为列表? [英] How do I convert a string to a list in Io?

查看:75
本文介绍了如何在Io中将字符串转换为列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我想将"hello"转换为list(104, 101, 108, 108, 111)list("h", "e", "l", "l", "o")

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

到目前为止,我已经创建了一个空列表,使用了foreach并将自己的每个项目都附加到列表中,但这并不是一种简洁的方法.

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.

推荐答案

我自己的建议:

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.

这篇关于如何在Io中将字符串转换为列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆