FoxPro does not contain a function for replacing a character string in anASCII text file. One way to do this is to use low-level file functions. Asimpler way is to copy the text file to a memo field, make the change usingSTRTRAN(), and copy the memo field back to an ASCII file, as demonstratedbelow.
The following steps demonstrate this procedure:
Create an ASCII text file that contains the following sentence: This sentence demonstrates how a character string can be changed.
Create a database that contains only a memo field.
Append a blank record to that database.
Create a program that contains the following code.
USE <table>APPEND MEMO <memofield> FROM <ASCII file> OVERWRITETemp=STRTRAN(<memofield>,"demonstrates","shows")REPLACE <memofield> WITH TempCOPY MEMO <memofield> TO <ASCII file>
Run the program.
Open the ASCII file; the word "demonstrates" should now read "shows".
If the same ASCII filename is used in the APPEND MEMO and the COPY MEMOcommands, the file will be rewritten with the changes. The OVERWRITEparameter on the APPEND MEMO command is needed so that the current textfile overwrites the existing contents of the memo field. This technique canalso be used to remove escape codes and page formatting from files byplacing the characters to remove in the STRTRAN() function.
Microsoft FoxPro 2.0, Microsoft FoxPro 2.5b for MS-DOS, Microsoft FoxPro 2.5a, Microsoft FoxPro 2.5b for MS-DOS, Microsoft FoxPro 2.6 for MS-DOS, Microsoft FoxPro 2.5b, Microsoft FoxPro 2.5a, Microsoft FoxPro 2.5b, Microsoft FoxPro 2.6 Standard Edition, Microsoft FoxPro 2.5b for Macintosh, Microsoft Visual FoxPro 3.0 Standard Edition, Microsoft Visual FoxPro 6.0 Professional Edition, Microsoft Visual FoxPro 7.0 Professional Edition, Microsoft Visual FoxPro 8.0 Professional Edition, Microsoft Visual FoxPro 9.0 Professional Edition