'use to prepare data of "123.csv"
'2014-7-11, by Colin Cheng
'constants
'what data file to be deal with
fileFullPath=InputBox("filepath and name, please")
'do not use OpenTextFile of Scripting.FileSystemObject, cause "utf-8"
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile(fileFullPath)
strData = objStream.ReadText()
objStream.Close
'remove \n from none quotation mark leading newline
content2write=ReplaceStr(strData,"(\n)([^""])","$2")
objStream.Open
objStream.WriteText content2write,0 ' 1 Writes a text string and a line separator character to a Stream object.
objStream.SaveToFile fileFullPath,2 ' 2 Overwrites the file with the data from the currently open Stream object
objStream.Close
'use regular expression to replace/remove some string
Function ReplaceStr(sourStr, patrn, replStr)
Dim regEx
Set regEx = CreateObject("vbScript.RegExp")
regEx.Pattern = patrn ' what to find
regEx.Global = True 'match all
regEx.IgnoreCase = True
ReplaceStr = regEx.Replace(sourStr, replStr)
End Function
阅读(2354) | 评论(0) | 转发(0) |