How to Replace a String in a Text FileID: Q113278 2.00 2.50 2.50a 2.50b 2.60 | 2.50 2.50a 2.50b 2.60 3.00 | 2.50b kbprg
The information in this article applies to:
SUMMARYFoxPro does not contain a function for replacing a character string in an ASCII text file. One way to do this is to use low-level file functions. A simpler way is to copy the text file to a memo field, make the change using STRTRAN(), and copy the memo field back to an ASCII file, as demonstrated below.
MORE INFORMATIONThe following steps demonstrate this procedure: 1. Create an ASCII text file that contains the following sentence:
2. Create a database that contains only a memo field.
3. Append a blank record to that database. 4. Create a program that contains the following code:
5. Run the program.
6. 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 MEMO commands, the file will be rewritten with the changes. The OVERWRITE parameter on the APPEND MEMO command is needed so that the current text file overwrites the existing contents of the memo field. This technique can also be used to remove escape codes and page formatting from files by placing the characters to remove in the STRTRAN() function. Additional reference words: VFoxWin 3.00 FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.60 KBCategory: kbprg KBSubcategory: FxprgGeneral
|
Last Reviewed: May 1, 1996 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |