dataslinger
Programmer
Hello,
I need to programmatically read in a text file that are occasionally sprinkled with misplaced single carriage returns (hex 0D/dec 13) or line feeds (hex 0A/dec 10) and then eventually import to a table. When the CR/LF characters are together in a proper pair, I would like to keep them, otherwise replace them with a space. I have tried various combinations of CHRTRAN, CHRTRANC, STRTRAN, and STRCONV with hex and decimal notation but I cannot get VFP to replace the carriage returns no matter what I do.
There are a few different replacement sequences that would work, but something like this should be straight-forward:
Any ideas?
I would like to work natively from text in stock VFP9, no third party tools please. Files are potentially large, if there's something better than FILETOSTR, advice on that is also appreciated.
thanks in advance
I need to programmatically read in a text file that are occasionally sprinkled with misplaced single carriage returns (hex 0D/dec 13) or line feeds (hex 0A/dec 10) and then eventually import to a table. When the CR/LF characters are together in a proper pair, I would like to keep them, otherwise replace them with a space. I have tried various combinations of CHRTRAN, CHRTRANC, STRTRAN, and STRCONV with hex and decimal notation but I cannot get VFP to replace the carriage returns no matter what I do.
There are a few different replacement sequences that would work, but something like this should be straight-forward:
Code:
cFile = "mytestfile.txt"
cString = FILETOSTR(cFile)
cString = CHRTRANC(cString,CHR(13),"|") && CR with a pipe, this replacement fails for some reason
cString = CHRTRANC(cString,CHR(10),"|") && LF with a pipe, this replacement works fine
cString = STRTRAN(cString,”||”,CHR(13)+CHR(10)) && double pipes to CR/LF pair
cString = CHRTRANC(cString,"|",CHR(32)) && remaining pipes to spaces
STRTOFILE(cString,"myoutput.txt")
Any ideas?
I would like to work natively from text in stock VFP9, no third party tools please. Files are potentially large, if there's something better than FILETOSTR, advice on that is also appreciated.
thanks in advance