复制代码
- Set fso = CreateObject("Scripting.FileSystemObject")
- set file = fso.OpenTextFile("a.txt")
- Do Until file.AtEndOfStream
- strLine = file.ReadLine
- If strLine <> "" Then
- ReDim PreServe ar(n)
- strIn = strIn & "$" & strLine & " "
- ar(n) = strIn : n = n + 1
- End If
- Loop
- For i = CLng(UBound(ar)/2) to 0 step -1
- ar1 = Split(strIn,ar(i))
- If UBound(ar1) > 1 Then
- For j = 1 to UBound(ar1) - 1
- WriteToFile Split(ar1(j)),Split(ar(i))
- Next
- Exit For
- End If
- Next
- MsgBox "OK"
- Sub WriteToFile(ar2,ar3)
- If UBound(ar2) >= 1 Then
- strOut = Mid(ar2(UBound(ar2)-1),2)
- Else
- strOut = Mid(ar3(UBound(ar3)-1),2)
- End If
- fso.OpenTextFile("b.txt",8,True).WriteLine strOut
- End Sub
你是不是这个意思?有些好奇为啥要从后往前读复制代码
- 'f是打开的文本
- a=len(f.readall)
- f.skip(a-1)
- msgbox f.read(1)
include <stdio.h> include <stdlib.h> int main(int argc, char *argv[] ) { FILE *fp = fopen("tmp.txt", "rb"); char c; int size; int offset = -1; //定位到文件末尾 fseek( fp, 0, SEEK_END ); //末尾的offset size = ftell(fp); int count = 0; //只捕获除换行符以外的倒数3个字符 while ( count < 3 && abs(offset) <= size ) { fseek( fp, offset--, SEEK_END ); c = getc( fp ); if ( c != 13 && c != 10 ) { count++; printf("%c\n", c); } } return 0; } |
复制代码
- Set fso = CreateObject("Scripting.FileSystemObject")
- set file = fso.OpenTextFile("a.txt")
- Do Until file.AtEndOfStream
- strLine = file.ReadLine
- If strLine <> "" Then
- ReDim PreServe br(n)
- strIn = strIn & "$" & strLine & " "
- br(n) = strIn
- n = n + 1
- End If
- Loop
- n = n - 1
- cr = Split(strIn)
- strIn = ""
- ReDim ar(n)
- For i = 0 To n
- j = cr(n - i)
- strIn = strIn & j & " "
- ar(i) = strIn
- Next
- For i = CLng(UBound(ar) / 2) to 0 step -1
- ar1 = Split(strIn, ar(i))
- If UBound(ar1) > 1 Then
- For j = 1 to UBound(ar1) - 1
- WriteToFile Split(ar1(j)), Split(ar(i))
- Next
- Exit For
- End If
- Next
- MsgBox "OK"
- Sub WriteToFile(ar2, ar3)
- If UBound(ar2) >= 1 Then
- strOut = Mid(ar2(UBound(ar2) - 1), 2)
- Else
- strOut = Mid(ar3(UBound(ar3) - 1), 2)
- End If
- fso.OpenTextFile("b.txt",8,True).WriteLine strOut
- End Sub
欢迎光临 批处理之家 (http://bathome.net./) | Powered by Discuz! 7.2 |