Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find/Replace in Notepad 1

Status
Not open for further replies.

vegetablejello

Programmer
Dec 27, 2013
2
US
I am looking to do a find/replace in a tab delimited text document before i import the file into a dbf structure. The problem is the tab delimited text document has double quotes in it and when i use this command "APPEND FROM &myfile delimited WITH TAB", the double quotes is throwing it all off. The only way I found to fix is to manually open up the text document and find/replace there. I never tried to access notepad and do a find/replace before so i may be starting this problem the wrong way. So far I can only open notepad, but can not figure out how to do anything else with it.

LOCAL oShell AS WScript.Shell
oShell = CREATEOBJECT("WScript.Shell")
oShell.Run("notepad &myfile", 0)
 
Why not do this in VFP?
Code:
lctextFile = FILETOSTR(myfile)
lctextFile = STRTRAN(lctextFile, ["], []) && Find and replace doble quotes here
STRTOFILE(lctextFile, myfile)

Borislav Borissov
VFP9 SP2, SQL Server
 
That works great.

I also added a line in there so you don't get asked to overwrite. (Assuming there is not a way to do that with the current code?)

Code:
lctextFile = FILETOSTR(myfile)
lctextFile = STRTRAN(lctextFile, ["], []) && Find and replace doble quotes here
[b]ERASE (myfile)[/b]
STRTOFILE(lctextFile, myfile)
 
Just add SET SAFETY OFF :)

Borislav Borissov
VFP9 SP2, SQL Server
 
It's a good policy to keep SAFTEY set to OFF throughout the running of your application. If you don't, it's possible that the user will see a confirmation prompt whenever the program wants to delete or overwrite a file. The user won't know why the prompt appears, and will usually play it safe, and will deny permission to overwrite. So the command that initiates the overwriting doesn't get executed, which means your program does not behave as you expect.

Of course, it makes sense keep SAFETY set to ON in the development environment, but that's another matter.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Or use the simpler version:
APPEND FROM &myfile DELIMITED :)
Since the default for a DELIMITED file IS with tabs and quotes this should do the trick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top