简体   繁体   中英

Splitting a string into multiple strings after a specified character in Ruby

I am trying to create a script that takes in a string with an unknown number of parts that are separated by ';' .

"blah blah one; blah blah two"

I tried to use the (?: re) example from rubydocs but had no luck with it. Can someone show me the best way to do this?

you can just use the split method

a='blah blah blah;blah foo blah'.split(";")

the parts will be store in index from 0 to 1 (in the above example )

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