tmp = []
fin.each_line do |line|
if line =~ /include.*?xercesc.*?>/
line.sub!(/(.*)<.*\/(.*?)>(.*)/, '\1"\2"\3')
end
tmp <<line
end
fin.close
# puts tmp.join()
fout = File.new("C:\\2.txt", "w")
fout.write(tmp.join())
fout.close
测试输入文件1.txt:
this is the first line
</include abc_xercesc.h>
xy <aaa/include 123_xercesc.c>zd
测试输出文件2.txt:
this is the first line
"include abc_xercesc.h"
xy "include 123_xercesc.c" zd
可以使用如Typhoeus, Restclint等第三方类库 详细使用方法可以看 github项目上的说明原生可以使用core-lib中的 'open-uri'
require "open-uri"
Net::HTTP.post_form(uri, params)