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.
假设有这个文本文件:
abcd,efgh,ijkl mnop,qrst 12345,78 poqs,90st
我想读取字符串,直到","or"\t"或"\n",以先到者为准。
","
"\t"
"\n"
有没有 Ruby 方法可以做到这一点?
我认为这样的事情会起作用:
open('file.txt').read.split(/\t\n,/)
基本上打开文件,获取文件的字符串输出并在制表符、换行符或逗号上拆分。
File.read('file.txt').scan(/\w+/)
无论使用什么分隔符,它都会扫描所有单词。