473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Find a string in a text file, replace it with space and save

Vic
Hi,
With VBA code from MSAccess, how to search for a string in another
text file, and replace it with space and then save it under the same
name? Your help is greatly appreciated.
Rgds
Nov 13 '05 #1
4 17451
li*****@uq.edu.au (Vic) wrote in message news:<f4**************************@posting.google. com>...
Hi,
With VBA code from MSAccess, how to search for a string in another
text file, and replace it with space and then save it under the same
name? Your help is greatly appreciated.
Rgds


A way to do it. I am sure there are others.

dim fso as object
dim txtStr as object
dim strHolder as string
dim strFileToFix as string

strFileToFix = "PATHTO FILE"

set fso = wscript.createobject("scripting.filesystemobject")

set txtStr = fso.opentextfile(strFileToFix,1,false,0)

strHolder = txtstr.readall

txtStr.close

set txtStr = nothing

strHolder = replace(strHolder,"string to find",space(0),1,-1,vbtextcompare)

set txtStr = fso.createtextfile(strFileToFix,true,false)

txtStr.write(strHolder)

txtStr.close

set txtStr = nothing
Nov 13 '05 #2
Thanks a lot. Is there is a way to search the file one line by one line?
It's actually a series of records, in each line, i need to find all d
with a comma behind and replace it with space. Then write it out.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3
Vic Li <li*****@uq.edu.au> wrote in message news:<41**********************@news.newsgroups.ws> ...
Thanks a lot. Is there is a way to search the file one line by one line?
It's actually a series of records, in each line, i need to find all d
with a comma behind and replace it with space. Then write it out.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Try this:

dim fso as object
dim txtStr as object
dim strHolder as string
dim strFileToFix as string
dim strTemp

strFileToFix = "PATHTO FILE"

set fso = wscript.createobject("scripting.filesystemobject")

set txtStr = fso.opentextfile(strFileToFix,1,false,0)

do until txtStr.atendofstream

strTemp = txtStr.readline

strTemp = replace(strTemp,"string to
find",space(1),1,-1,vbtextcompare)

strHolder = strHolder & strTemp & vbcrlf 'not sure you need vbcrlf or
not i think you do

next

txtStr.close

set txtStr = nothing

set txtStr = fso.createtextfile(strFileToFix,true,false)

txtStr.write(strHolder)

txtStr.close

set txtStr = nothing

Just a side note. I would suggest you pick up a copty of
VBScript in a Nutshell published by O'Reilly. The first
edition is OK and is just a tremendous resource. No real need to get
the second edition if you want to be cheap. Dirt cheap used on the
internet.

Finally there was a bug in the first post should be space(1) not
space(0).
Nov 13 '05 #4
Hi all,
Thanks a lot. Works well now!! Great!!
Rgds,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Bernd.Moos | last post by:
Given the following XML document: <text> <p> <w>Ronaldo</w> <w>scoredw> <w>the</w> <w>1</w> <c>:</c> <w>1</w>
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
9
by: al jones | last post by:
Sorry, it's getting late and I'm tired. I'm trying to fill a richtect box with text derived from the array I was asking about earlier (thank you). I'm not sure what I'm seeing - since most of...
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
5
by: peter | last post by:
Hello all, I'm looking for an advice. Example (one block in ascii file): $------------------------ NAME='ALFA' CODE='x' $------------------------
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
4
by: moondaddy | last post by:
I need to edit the text in many files so I'm writing a small routine to do this. First I have a method that loops through all the files in a directory and passes the full file path to another...
3
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.