The following is somewhat unsophisticated but works.
Convert the text file to a table, locate the text file line, (record), replace with new string and convert back to a text file
CREA TABLE temp (cLine c(254))
APPE FROM MyText.txt DELIMITED
SELE TEMP
* LOCATE FOR etc
* REPLACE MyText.cline WITH etc
lcFile = []
SCAN
[tab]lcFile = lcFile + ALLT(TEMP.cLine) + CHR(13)
ENDS
STRTOFILE(lcFile,[MyText.txt])
Chris
How do you identify the line you want to replace? And what sort of a file is it? It's pretty easy to slice and dice a text file, but a little info would be helpful.
Have you looked at FILETOSTR() ALINES() and STRTOFILE()? They make it pretty easy to work with a file on a line to line basis.
I knew I'd seen it before. According to the programmers guide, appendex "Visual FoxPro System Capabilities" the maximum number of characters of a character string or memory variable is ... 16,777,184. IOW no need to worry unless you're trying to put the library of congress into one variable. BTW, the programmer's guide can be found under 'Using Visual FoxPro' in the documentation.
Rick's use of STRTRAN() is the shortest way to achieve the result ITflash is looking for.
The conversion of the text file to a table idea has merit in that you can additionally insert lines into a text file through the use of the INSERT command.
What I tend to forget is that the INSERT command, (not to be confused with INSERT- SQL), is no longer documented, and there may be those unfamiliar with its syntax.
GO 123
INSERT BLANK
REPL TABLENAME.fieldname WITH [Hello World]
will insert a blank record immediately after record 123, anabling the REPLACE to take effect into the new blank record.
The other syntax is
INSERT BLANK BEFORE
which will open up the record in the Edit window.
One important thing to note is that INSERT BLANK [BEFORE] will not work on buffered data.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.