仅删除空字段中的尾随空格和空格

时间:2016-11-09 01:59:40

标签: vbscript

我有一个包含以下数据的CSV

  

" 01"," 567"," ","这是一条消息"

我需要删除空白字段中的尾随空格和空格,同时将空格留在数据之间。

我的代码:

Dim inStream : Set inStream...

With inStream

  .open

  .type = 2

  .charset = "utf-8"

  .loadfromfile src

  Dim outStream : Set outStream...

  outStream.open

  outStream.type = 2

  While Not .EOS

    arrLine = split(.read, ",")

    strLine = trim(arrLine(0))

    If ubound(arrLine) > 0 Then
      For intField = 1 To ubound(arrLine)
        strLine = strLine & "," & trim(arrLine(intField))
      Next
    End If

    outStream.write(strLine)
    outStream.savetofile dest, create
  WEnd

  outStream.close

  .close

End With

1 个答案:

答案 0 :(得分:0)

您可以将CSV行拆分为数组,然后循环并在每个项目上使用“修剪”功能。 在Google上有令人惊讶的好像这样的vbscript示例。