Hi,
We receive files from the French company's main frame and it has *EOF* characters embedded in the names, which breaks the processing of the file in the middle. The problem is that the program does not read past this character, so I cannot replace it. The hex character we are getting is 1A.
Any help would be greatly appreciated.
Alla
Have you tried the Binary Functions? BinaryReplace() will handle any of the characters.
Jim
A crude example:
strFile = 'c:\temp\EmbeddEof.txt'
strBuf = 'This file has an ':Num2Char(26):' in the middle':@crlf
; Creat a file with embedded EOF
FilePut(strFile, strBuf)
nSize = FileSize(strFile)
hBuf = BinaryAlloc(nSize*3)
BinaryReadEx(hBuf, 0, strFile, 0, nSize)
BinaryReplace(hBuf, Num2Char(26), 'EOF', 0)
strText = BinaryPeekStr(hBuf, 0, nSize)
BinaryFree(hBuf)
Message("File Text", strText)
Thank you very much! My issue was Num2Char(26), did not know how to tell WB to replace '1A'. Learned a lot about binary buffer use, great set of tools. Here is what I ended with and it works:
filename = 'C:\Develop\BadChar TEST File.txt'
newfile = 'C:\Develop\BadChar TEST File Fixed.txt'
debug(1)
nSize = FileSize(filename)
hBuf = BinaryAlloc(nSize+200)
BinaryReadEx(hBuf, 0, filename, 0, nSize)
BinaryReplace(hBuf, Num2Char(26), ' ', 0)
BinaryWrite( hBuf, newfile )
BinaryFree(hBuf)
Exit
I think to make a UDF out of it with IntControl(73...) just in case. But that one is later. Thank you all!
Another approach is to convert directly from the hex value to an ANSI character:
strEof = ChrHexToString('1A')
Oh, this is great, as I have A4, A5, and expect some more. Thank you!
If you have multiple characters to remove, you might consider using a combination of the FileGet and StrClean functions to perform the task in one pass over the file.
StrClean did not work while 1A was there, it would not go beyond 1A. After it was removed StrClean should work, I will try it on the next change.
Thank you,
Alla
I have no problems getting StrClean to remove multiple characters in a file containing the 0x1a character.