思路:
1.全部转换为ASCII,用逗号分开
2.ASCII打散成数组,ASCII依次还原为字符,加条件加空格
VBS代码如下:
程序代码:
Dim i, str, ascstr,l Const ForReading = 1, ForWriting = 2,ForAppend=8 Dim fso, f,openFile Set fso = CreateObject("Scripting.FileSystemObject") Set Stm =CreateObject("ADODB.Stream") Stm.Type=2 '2-文本模式,1-二进制模式 Stm.Mode=3 '3-读写,1-读,2-写 Stm.CharSet= "gb2312" 'Unicode,utf-8,ASCII,gb2312,big5,gbk Stm.Open Stm.LoadFromFile "1.txt" str = Stm.ReadText Stm.Close Set Stm=Nothing For i = 1 To Len(str) ascstr = ascstr & "," & CStr(Asc(Mid(str, i, 1))) j = right(ascstr,len(ascstr)-1) Next 'MsgBox j Set f = fso.OpenTextFile("ASCII代码.txt",ForAppend, True) f.Write j f.Close Set openFile=fso.OpenTextFile("ASCII代码.txt",1,True) '1表示只读,2表示可写,8表示追加,True表示目标文件存在时是否覆盖 AsciiStr = openFile.ReadAll openFile.Close S=split(AsciiStr,",") '以空格作为分隔符 For i=0 to ubound(S) if i+1 <= ubound(S) then '防止下标越界 if S(i)<0 and S(i+1)>=0 then '加入空格的时机,条件 SaveFiles(Chr(S(i))) SaveFiles(" ") else SaveFiles(Chr(S(i))) end if else SaveFiles(Chr(S(i))) end if Next Function SaveFiles(content) '文件内容 Const ForReading = 1, ForWriting = 2,ForAppend=8 Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("已处理文本.txt",ForAppend, True) f.Write content End Function