2

我有一个类似 .CSV 的文件,我想对它做两件事之一。

文件中的数据如下所示:

"BRANCH","CARD","BILL_TYPE","AUTH_CODE","INVOICE","UNIT","EMP_NUM","TRIP","TRAILER","HUB/SPEED","VEH_LICENSE","DRIVER","DATE","TIME","CHAIN","IN_NETWORK","TS#","TS_NAME","TS_CITY","TS_STATE","PPG","NET_PPG","FUEL_GALS","FUEL_AMT","RFR_GALS","RFR_AMT","CASH","MISC","INV_TOTAL","FEE","DISC","INV_BALANCE",1.00,1.00,"E","004ACS","02812","365","-","-","0",0.00,"-","JOHN S  ",11/4/2013,"16:18:49E","IC","N",3257.00,"IRVING HOULTON","HOULTON","ME",3.95,3.95,121.57,480.08,0.00,0.00,0.00,0.00,480.08,1.50,0.00,481.58
"BRANCH","CARD","BILL_TYPE","AUTH_CODE","INVOICE","UNIT","EMP_NUM","TRIP","TRAILER","HUB/SPEED","VEH_LICENSE","DRIVER","DATE","TIME","CHAIN","IN_NETWORK","TS#","TS_NAME","TS_CITY","TS_STATE","PPG","NET_PPG","FUEL_GALS","FUEL_AMT","RFR_GALS","RFR_AMT","CASH","MISC","INV_TOTAL","FEE","DISC","INV_BALANCE",1.00,2.00,"E","014ACI","976234","430","-","-","0",0.00,"-","STACY    ",11/4/2013,"00:21:16E","F","Y",8796.00,"PILOT 405","TIFTON","GA",3.77,3.77,172.65,650.73,0.00,0.00,0.00,0.00,650.73,1.50,0.00,652.23
"BRANCH","CARD","BILL_TYPE","AUTH_CODE","INVOICE","UNIT","EMP_NUM","TRIP","TRAILER","HUB/SPEED","VEH_LICENSE","DRIVER","DATE","TIME","CHAIN","IN_NETWORK","TS#","TS_NAME","TS_CITY","TS_STATE","PPG","NET_PPG","FUEL_GALS","FUEL_AMT","RFR_GALS","RFR_AMT","CASH","MISC","INV_TOTAL","FEE","DISC","INV_BALANCE",1.00,1.00,"E","004ACS","02812","365","-","-","0",0.00,"-","JOHN S  ",11/4/2013,"16:18:49E","IC","N",3257.00,"IRVING HOULTON","HOULTON","ME",3.95,3.95,121.57,480.08,0.00,0.00,0.00,0.00,480.08,1.50,0.00,481.58
"BRANCH","CARD","BILL_TYPE","AUTH_CODE","INVOICE","UNIT","EMP_NUM","TRIP","TRAILER","HUB/SPEED","VEH_LICENSE","DRIVER","DATE","TIME","CHAIN","IN_NETWORK","TS#","TS_NAME","TS_CITY","TS_STATE","PPG","NET_PPG","FUEL_GALS","FUEL_AMT","RFR_GALS","RFR_AMT","CASH","MISC","INV_TOTAL","FEE","DISC","INV_BALANCE",1.00,2.00,"E","014ACI","976234","430","-","-","0",0.00,"-","STACY    ",11/4/2013,"00:21:16E","F","Y",8796.00,"PILOT 405","TIFTON","GA",3.77,3.77,172.65,650.73,0.00,0.00,0.00,0.00,650.73,1.50,0.00,652.23

每一行都以这个重复的文本开头:"BRANCH","CARD","BILL_TYPE","AUTH_CODE","INVOICE","UNIT","EMP_NUM","TRIP","TRAILER","HUB/SPEED","VEH_LICENSE","DRIVER","DATE","TIME","CHAIN","IN_NETWORK","TS#","TS_NAME","TS_CITY","TS_STATE","PPG","NET_PPG","FUEL_GALS","FUEL_AMT","RFR_GALS","RFR_AMT","CASH","MISC","INV_TOTAL","FEE","DISC","INV_BALANCE",

我想做的是...

选项1:

  1. 将重复的文本放在一个字符串中
  2. 删除字符串中的最后一个字符
  3. 使用 no 中的字符串从文件中删除所有其他重复文本。1
  4. 保存 .CSV 文件

选项 2:

  1. 将重复的文本放在一个字符串中
  2. 删除字符串中的最后一个字符
  3. 每个循环/每一行我都会跳到第 305 列
  4. 保存 .CSV 文件

我如何在经典 ASP 中做到这一点?

4

1 回答 1

3

A .ReadLine()/2 文件方法:

  Dim tsIn  : Set tsIn  = goFS.OpenTextFile("..\data\19936645.csv")
  Dim tsOut : Set tsOut = goFS.CreateTextFile("..\data\19936645-2.csv")
  Dim sFrs  : sFrs      = tsIn.ReadLine()
  Dim sLast : sLast     = """INV_BALANCE"","
  Dim nCutP : nCutP     = Instr(sFrs, sLast) + Len(sLast)
  Dim sHead : sHead     = Left(sFrs, nCutP - 2)
  Dim sLine
  tsOut.WriteLine sHead
  tsOut.WriteLine Mid(sFrs, nCutP)
  Do Until tsIn.AtEndOfStream
     sLine = tsIn.ReadLine()
     If 1 = Instr(sLine, sHead) Then
        tsOut.WriteLine Mid(sLine, nCutP)
     Else
        WScript.Echo "Bingo!"
     End If
  Loop
  tsOut.Close
  tsIn.Close

这将创建一个带有列标题的新 .csv。

于 2013-11-12T19:14:33.997 回答