Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个这样的字符串:
14.015_KNECHT_178178
我怎样才能拆分它,以便:
art = 14.015 man = KNECHT
如您所见,分隔符是_.
_
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"
试试这个
art,man= "14.015_KNECHT_178178".split(/_/)
有关#split的更多详细信息,请点击此处