On Sat, 11 Jun 2005 08:35:00 -0400, Benjamin Slade wrote:
>I want to do a search-and-replace in an ascii file (which contains
>both text and numbers), and manipulate numbers in certain ranges
>(by adding +1 or +2, etc. to each number, in a certain range, in
>the text file).
>
>I can see how to search-and-replace text strings in a file, but
>not how to manipulate (add/subtract) values from numbers in
>certain ranges.
Benjamin:
Perhaps the following little macro could help.
The comments should explan it...
Num_Push(91,95) // save used registers
Reg_Push(99,99)
// the range of numbers which should be manipulated
#91 = 1970
#92 = 1980
//value to add/subtract
#93 = 1
Begin_Of_File
repeat(ALL) {
Search("|D|D|D|D", NOERR+ERRBREAK) // somehow search the next
// number, here 4 digits
#94 = Num_Eval(SUPPRESS) // get its value
#95 = Chars_Matched // and length
if ((#94 >= #91) && (#94 <= #92)) { // if in range
#94 += #93 // add/subtract
Num_Str(#94, 99, LEFT+NOCR) // write new value as text
// into temp. register
Reg_Ins(99, OVERWRITE) // overwrite old with
// new value
} else {
Char(#95) // else skip this number
}
}
Reg_Pop(99,99) // restore used registers
Num_Pop(91,95)
Christian