Topic: editing (mathematically) numerical values in ascii (1 of 4), Read 40 times
Conf: Search and Replace
From: Benjamin Slade
Date: Saturday, June 11, 2005 08:35 AM

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.

 


Topic: Re: editing (mathematically) numerical values in ascii (2 of 4), Read 42 times
Conf: Search and Replace
From: Christian Ziemski
Date: Saturday, June 11, 2005 12:17 PM

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

 


Topic: Re: editing (mathematically) numerical values in ascii (4 of 4), Read 42 times
Conf: Search and Replace
From: Ted Green
Date: Sunday, June 12, 2005 12:00 AM

At 12:17 PM 6/11/2005, you wrote:
>>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...

Thank you for the informative macro Christian.

Ted.

 


Topic: editing (mathematically) numerical values in ascii (3 of 4), Read 42 times
Conf: Search and Replace
From: Benjamin Slade
Date: Saturday, June 11, 2005 09:52 PM

Many thanks for your detailed response! I'll try it.

cheers,
Ben