Chinaunix首页 | 论坛 | 博客
  • 博客访问: 156981
  • 博文数量: 31
  • 博客积分: 2085
  • 博客等级: 大尉
  • 技术积分: 350
  • 用 户 组: 普通用户
  • 注册时间: 2005-11-07 13:16
文章分类

全部博文(31)

文章存档

2014年(1)

2011年(4)

2010年(6)

2009年(2)

2008年(2)

2007年(5)

2006年(8)

2005年(3)

我的朋友

分类: 信息化

2014-07-16 17:12:42

'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) |
0

上一篇:博客已升级,请注意变更地址

下一篇:没有了

给主人留下些什么吧!~~