每个Ruby csv - 清理字符?

时间:2014-04-25 19:20:42

标签: ruby csv replace foreach

我有以下代码,它读取csv的每一行并清理每一行。这些行都是路径\文件名目录。我遇到一个问题,脚本找不到路径\文件,因为文件名中有一个 - 在其中。 - (破折号)由ruby读取为\ x96。有谁知道如何让它不这样做,并阅读 - 作为破折号?

这就是我所拥有的,但它不起作用:

CSV.foreach("#{batch_File_Dir_sdata}") do |ln|
        line_number += 1
        pathline = ln.to_s
        log_linemsg = "Source #{line_number}= #{pathline}"
        log_line = ["#{$cname}","#{log_linemsg}","","",]
        puts log_linemsg
        insert_logitems(connection, table_namelog, log_line)
        if pathline.include?("\\")
            cleanpath = pathline.gsub!("\\\\","\\")
            #cleanpath = cleanpath.gsub!("[","")
            #cleanpath = cleanpath.gsub!("]","")
            cleanpath.gsub!("\"","")
    #THIS IS THE LINE WHERE I AM TRYING TO FIX THE ISSUE        
            cleanpath.gsub!("\\x96","\-")
            cleanpath.slice!(0)
            cleanpath.chop!
            #puts "Clean path - has backslash\n#{cleanpath}"
        else
            cleanpath = pathline
            #puts "#{cleanpath}"
            #puts "Clean path - has NO backslash\n#{cleanpath}"
        end

非常感谢任何帮助。

0 个答案:

没有答案