gpt4 book ai didi

ruby - 如何进一步分解数组中的字符串

转载 作者:太空宇宙 更新时间:2023-11-03 17:15:29 25 4
gpt4 key购买 nike

我试图分解属于一个字符串的一个句子,但将其分解为各自数组中的字母,并将其放在一个大数组中。

所以我的意思是:

def break("hello world")

方法中的代码将导致:

[["h","e","l","l","o], ["w","o","r","l","d"]]

我之所以需要它,是因为我以后可以按照我想要的顺序重新排列字母。我尝试了几件事,但没有成功。

最佳答案

"hello world".split.map &:chars
# => [["h", "e", "l", "l", "o"], ["w", "o", "r", "l", "d"]]

关于ruby - 如何进一步分解数组中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26375022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com