0

我有一个这样的字符串:

"John Godson Michael Meyer Ludovicio Sforza Cezar Borgia Alessandro Batista"

如何将此字符串转换为字符串数组,例如

# ["John", "Godson", "Michael Meyer" (...)]
4

2 回答 2

5

只需使用字符串#split

"John Godson Michael Meyer Ludovicio Sforza Cezar Borgia Alessandro Batista".split
于 2012-08-23T11:02:14.727 回答
1
"John Godson Michael Meyer Ludovicio Sforza Cezar Borgia Alessandro Batista".split(' ')
#=> ["John", "Godson", "Michael", "Meyer", "Ludovicio", "Sforza", "Cezar", "Borgia", "Alessandro", "Batista"]
于 2012-08-23T11:03:42.620 回答