0

我有一个这样的字符串:

14.015_KNECHT_178178

我怎样才能拆分它,以便:

art = 14.015
man = KNECHT

如您所见,分隔符是_.

4

2 回答 2

2

string#split 可以做到这一点。

>> (art,man,foo) = "14.015_KNECHT_178178".split '_'
=> ["14.015", "KNECHT", "178178"]
>> p art
"14.015"
=> "14.015"
>> p man
"KNECHT"
=> "KNECHT"
>> p foo
"178178"
=> "178178"
于 2012-08-28T13:38:42.810 回答
2

试试这个

art,man= "14.015_KNECHT_178178".split(/_/)

有关#split的更多详细信息,请点击此处

于 2012-08-28T13:40:29.283 回答