我有两个文件,"test1.rb","test2.rb"."test1.rb" "\t"在第82和84行包含TAB()字符.
我想打印出这样的:
test1.rb: 82 (it means that there are TAB included in the line of 82).
test1.rb: 84 (it means that there are TAB included in the line of 84).
Run Code Online (Sandbox Code Playgroud)
def check_tab file
open(file){|io| io.each_line.with_index(1){|s, l| puts "#{file}: #{l}" if s =~ /\t/}}
end
%w[test1.rb test2.rb].each{|f| check_tab(f)}
Run Code Online (Sandbox Code Playgroud)