我有一个文本文件,如下所示
"asdf","dfgv","asd","sdgs"
"sfgf","xcbvcvb","gsfgf","sdvxc"
"asfdfg","fbgdfg","sdfsd","fdg"
"bdg","sdf","fgfdg","fcg"
"sdf","fbcx","ckvknm","fklf"
"xv","asds","r","cxv"
但我想要看起来像这样的输出
asdf,dfgv,asd,sdgs
sfgf,xcbvcvb,gsfgf,sdvxc
asfdfg,fbgdfg,sdfsd,fdg
bdg,sdf,fgfdg,fcg
sdf,fbcx,ckvknm,fklf
xv,asds,r,cxv
我已经浏览了以下链接并将代码从#1更改为打印#1。但问题是,我希望将此文件批量插入到sql server中。因此,使用印刷品对我没有帮助。 Remove double quotation from write statement in vba
答案 0 :(得分:1)
您可以使用Replace
功能删除所有引号字符:
result = Replace(original_string, string_you_want_to_remove, replace_with )
example = Replace(original_string , CHR(34), "")
答案 1 :(得分:0)
只需做一个REPLACE()
[12] pry(main)> response.body
=> "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"TEXT/HTML; CHARSET=utf-8\"/><title>Error</title></head><body><H2>Error</H2><table summary=\"Error\" border=\"0\" bgcolor=\"#FEEE7A\" cellpadding=\"0\" cellspacing=\"0\" width=\"400\"><tr><td><table summary=\"Error\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\"><tr valign=\"top\" bgcolor=\"#FBFFDF\" align=\"left\"><td><STRONG>Error</STRONG></td></tr><tr valign=\"top\" bgcolor=\"#FFFFFF\"><td>This page can't be displayed. Contact support for additional information.<br/>The incident ID is: N/A.</td></tr></table></td></tr></table></body></html>"
答案 2 :(得分:0)
试试这段代码:
Sub CleanFile()
Dim fileName, FSO, rfile, wfile As Variant
Dim line As String, dotAt As Integer, newFileName As String
fileName = Application.GetOpenFilename(, , "Load Excel File", , False)
If fileName = "False" Then
MsgBox "No file chosen"
Exit Sub
End If
dotAt = InStrRev(fileName, ".")
newFileName = Left(fileName, dotAt - 1) + " - CLEAN.txt"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set rfile = FSO.OpenTextFile(fileName, 1) 'connection for reading
Set wfile = FSO.OpenTextFile(newFileName, 8, True, -1) 'connection for writing
Do Until rfile.AtEndOfStream
line = rfile.ReadLine
wfile.WriteLine Replace(line, """", "")
Loop
End Sub
答案 3 :(得分:0)
谢谢大家,但我找到了另一种使用批处理脚本删除双引号的方法,如下所示。
set objRe = new RegExp
objRE.Pattern = "\"""
objRE.Global = True
strFileName = "Source.txt"
set objFS = CreateObject("Scripting.FileSystemObject")
set objTS = objFS.OpenTextFile(strFileName)
strFileContents = objTS.ReadAll
objTS.Close
strNewContents = objRE.replace(strFileContents,"")
set objWS = objFS.CreateTextFile("Results.txt")
objWS.Write StrNewContents
objWS.close