ruby中的字符串分隔符--split

当字符串是以“:”隔开时,可以这样写:

column = str.split(/:/)

这样,column就是字符串每栏的值所构成的数组。

eg:

1 str = "Ruby in a shell:hello :2001:USA"
2 column = str.split(/:/)
3 p coulumn
4 
5 
6 #=>["Ruby in a shell", "hello ", "2001", "USA"]

可以看出,分隔后的元素是字符串型,组成了一个数组

原文地址:https://www.cnblogs.com/fish-101/p/10446513.html