why does macro command "replace()" print to Log window?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

why does macro command "replace()" print to Log window?

Bill Christens-Barry-2
Hi,

I'm trying to understand why when a macro runs the command "replace()" the result is printed into the Log window, a la:

    a = "string1";
    replace(a, "1", " that was altered");// ==> "string that was altered" printed in the Log window

I get this result using macOS 10.14.6 and also using Windows 7, both using recent ImageJ 1.52v updates, in all cases with debug mode turned OFF.

Moreover, I'm not sure where I should be looking in the source code to follow the action and understand this. I've tried looking at Functions.java and elsewhere, but haven't sorted this out.

Can anyone point me to an explanation and/or the relevant code?

Thanks,

Bill

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: why does macro command "replace()" print to Log window?

Michael Schmid
Hi Bill,

replace(string, old, new) does not modify the String. It *returns* the
modified String.
If a macro creates an output that is not assigned to a variable, it
prints the output on the Log.

So you need
   newString = replace(oldString, old, new);

See
https://imagej.nih.gov/ij/developer/macro/functions.html#replace

Michael
______________________________________________________________________


> I get this result using macOS 10.14.6 and also using Windows 7, both using recent ImageJ 1.52v updates, in all cases with debug mode turned OFF.
>
> Moreover, I'm not sure where I should be looking in the source code to follow the action and understand this. I've tried looking at Functions.java and elsewhere, but haven't sorted this out.
>
> Can anyone point me to an explanation and/or the relevant code?
>
> Thanks,
>
> Bill

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: why does macro command "replace()" print to Log window?

Bill Christens-Barry-2
In reply to this post by Bill Christens-Barry-2
Michael,

Ahh, a general principal I've overlooked - many thanks.

Bill

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html