简体   繁体   中英

Using more than one delimiter for .split method in Ruby

I want to split a string into an array by ";" , " " and "," delimiters in one line. Is there a way to do that without using regex?

Yes. Possible but with regex .

string.split(/[;, ]/)

只需用一个分隔符替换分隔符并将其拆分。

p "aaa;bbb ccc,ddd".tr(";,"," ").split  #=> ["aaa", "bbb", "ccc", "ddd"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM