数据导入类型来源

 
# to change this template, choose tools | templates
# and open the template in the editor.
 
#puts "hello world"
str = file.read('d:/csvtest.txt')
valuefile = file.new('d:/orig.txt','w')
$stdout = valuefile
str.gsub!(/\"|\+|\n/,'')
str.sub!(/select|select/,'')
#puts str
index = str.index(' where ')
#puts str[0..index]
str[index..-1] =''
arry = str.split(' from ')
colvalue = arry[0]
orivalue =arry[1]
value = []
value_hash = hash.new
while /\,/ =~ colvalue
  sign_index = colvalue.index(',')
  if colvalue[0..sign_index].count('(') == colvalue[0..sign_index].count(')')
 
    value << colvalue[0...sign_index].gsub('|',',')
    value[-1].gsub!("<span style="white-space: pre;"> </span>",'')
    value[-1].gsub!(" ",'')
    colvalue[0..sign_index] = ''
  else
    colvalue[sign_index] = '|'
  end
end
value << colvalue
puts value
puts "____" *20
valuefile.close
$stdout =stdout
puts "fgi"
#puts arry[0]
#puts 'sdf'  if "avagd".count('4') == 'aa'.count('a')
arry = orivalue.split(',')
for i in arry
  arry = i.split
  if arry.length == 2
    value_hash[arry[0]] = arry[1]
    # puts arry[1]
  end
end
finish = []
for i in value
  value_hash.each{|key,valueo|
 
    if /#{valueo}./ =~ i
      index = i.index("#{ valueo}\.")
      #puts index
      if index == 0
        puts i
        i[index..index + 1] = key
        finish << i
        #value.delete(i)
        # next
        # break
 
#      else /\(/ =~ i[index - 1...index]
#        puts i
#        i[index..index + 1] = key
#        finish << i
#        value.delete(i)
      end
 
    end
 
    # puts "#{key}=>#{value}"
  }
end
 
puts finish
#valuefile.close
#$stdout =stdout
##puts value_hash
 
def ishasoname hash,value,finish
  hash.each{ |key,hash_vl|
    hash_vl  = hash_vl.to_s
    hash_vl << '.'
    if index = value.index(hash_vl)
      if index == 0 or /\w/ =~ value[index - 1 ...index]
        value[index..index+1] = key
        puts value
        finish << value
 
        reuturn
      end
    end
 
  }
  puts value
  finish << value
  puts hash
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值