edit text file with an add function

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
dafe
Junior Coder
Posts: 23
Joined: Sun Apr 06, 2008 4:21 am

edit text file with an add function

Post by dafe » Sat Jun 14, 2008 6:19 am

Ok, i have what is probably a very simple question

on around line 92 (of 101 lines) of a vbscript file i have

Code: Select all

For i=1 To 100
What i'm wanting to do is replace this line by adding 100 to each number i.e.

Code: Select all

For i=101 To 200
and have it continue to do so up until

Code: Select all

For i=29901 To 30000
I'm having problems seperating each number from the string in order to add 100 to it, and then have the file rewrite itself with the new values as the string length changes from 14 up to 20 characters.

I'm assuming there is a simple method that i'm proabably missing. Does anyone have any suggestions to achieve this file rewrite?
--

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jun 18, 2008 1:09 pm

How about this:

Code: Select all

Let>line=For i=82 To 200

Position>i=,line,1,p1
MidStr>line,{%p1%+2},255,theNumber

Position> ,theNumber,1,p2
MidStr>theNumber,1,{%p2%-1},theNumber

Let>theNewNumber=theNumber+100

StringReplace>line,theNumber,theNewNumber,line
This uses a harcoded example. I would read though your input file line by line, writing out to a new text file as you go, look for existence of "For i=" at start of each line. If match then do the above code and write the new line out instead. At end replace old file with new file.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts