Forum Moderators: open

Message Too Old, No Replies

Writing to a txt file

Writing to a txt file

         

mavrick

2:47 pm on May 16, 2005 (gmt 0)

10+ Year Member



Hi

I need to write to a txt file, but I don’t want to replace the whole file, only certain text in the file.
Can this be done?
Using ASP.

Thanks

mrMister

10:39 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a bit crude, but it should do the job...

* Read File in to a string (Using the FileSystemObject)

* Do a Replace() or a RegEx Replace on the string

* Save String to File (Using the FileSystemObject)

Shout if you need anything explaining.

Hopefully someone else will come along with something more elegant!

mavrick

6:46 am on May 17, 2005 (gmt 0)

10+ Year Member



HI

Got the first part done...

Not sure about
"Do a Replace() or a RegEx Replace on the string"

thanks

larryhatch

7:01 am on May 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Am I missing something?

Wordpad will call up .txt files of most any size.
Just suck the file in and edit your changes at will.
Be sure to rename and save both old and new files in case of errors.
Done. -Larry

topr8

8:21 am on May 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



do you know the text that you want to replace?

if you know the text you want to replace it is simple...

newversion=replace(oldversion,'old text string','replacement text string')

topr8

8:27 am on May 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you can also use regex to do the replace, to replace against a list of words or everything between a predefined start and stop word or any other normal regex match.

you need to set a regex object to do this.

>>Am I missing something?

you are right larry but i think this needs to be done server side not locally.

mavrick

8:14 am on May 19, 2005 (gmt 0)

10+ Year Member



hi all
thanks for the help

What is the "regex". did some looking around the net... could not find anything...

please explain this may help?

mattglet

2:15 pm on May 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



History:
[en.wikipedia.org...]

Once you understand the basis, you can visit [regexlib.com...] for usage.

topr8

9:15 pm on May 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



regex (short for regular expressions) is straightforward - it is basically a way of matching strings.

the way you can implement regex in asp is not great, there is a built in object RegExp that you can use, a search for that should give you some tutorials.