4
考虑下面的输入采用分体式功能答案:差异而在Ruby中
file1, length1, name1, title1 = line2.split(/,\s*/)
我得到以下输出:
line1 = "Hey | Hello | Good | Morning"
line2 = "Hey , Hello , Good , Morning"
file1=length1=name1=title1=nil
使用“”以如下分割字符串
puts file1,length1,name1,title1
>Hey
>Hello
>Good
>Morning
但是,使用'|'到分割字符串我接收一个不同的输出:
file1, length1, name1, title1 = line2.split(/|\s*/)
puts file1,length1,name1,title1
>H
>e
>y
这两个字符串是除了分离符号(在第一种情况下一个逗号和在第二种情况下的配管)相同。我使用的分割函数的格式也是相同的,当然,除了分隔字符之外。是什么导致这种变化?
谢谢它回答了我的问题并清除了我的概念。 – randomuser15995183