Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby使用两个不同的分隔符拆分字符串_Ruby_String_Split - Fatal编程技术网

Ruby使用两个不同的分隔符拆分字符串

Ruby使用两个不同的分隔符拆分字符串,ruby,string,split,Ruby,String,Split,我想使用+或-作为分隔符拆分字符串 test.split//will被-。 test.split/\+/将由++分割。 我需要检查这两个字符。只需使用字符类,并在其中放入+和-即可 puts test.split(/[+-]/);

我想使用+或-作为分隔符拆分字符串

test.split//will被-。 test.split/\+/将由++分割。
我需要检查这两个字符。

只需使用字符类,并在其中放入+和-即可

puts test.split(/[+-]/);