Using a function that returns a string in the str.*() functions fails

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

Using a function that returns a string in the str.*() functions fails

Stein Rørvik
There seems to be a glitch in the macro parser when trying to use a function that returns a string as input in the str.*() functions:

The following fails:

run("Blobs (25K)");
if (getTitle().contains("blobs")) showMessage("this is the blobs image");

run("Blobs (25K)");
if (getTitle().endsWith("gif")) showMessage("this is a GIF image");


The following equivalent works:

run("Blobs (25K)");
imageTitle = getTitle();
if (imageTitle.contains("blobs")) showMessage("this is the blobs image");
if (imageTitle.endsWith("gif")) showMessage("this is a GIF image");


Another thing: It would be useful if it was mentioned in the macro functions documentation what version number these useful str.*() functions were introduced, so that one can insert the appropriate requires() statement before using them in a macro.


Stein

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

Re: Using a function that returns a string in the str.*() functions fails

Wayne Rasband-2
> On Mar 8, 2021, at 10:35 AM, Stein Rørvik <[hidden email]> wrote:
>
> There seems to be a glitch in the macro parser when trying to use a function that returns a string as input in the str.*() functions:
>
> The following fails:
>
> run("Blobs (25K)");
> if (getTitle().contains("blobs")) showMessage("this is the blobs image");
>
> run("Blobs (25K)");
> if (getTitle().endsWith("gif")) showMessage("this is a GIF image”);

This bug is fixed in the 1.53i29 daily build.

> Another thing: It would be useful if it was mentioned in the macro functions documentation what version number these useful str.*() functions were introduced, so that one can insert the appropriate requires() statement before using them in a macro.

I updated the documentation for the str.*() functions, under “String Functions” in the Macro Functions list, so it mentions the version of ImageJ required.

These string functions, where 's' is a string variable, are also available in ImageJ 1.52t and newer: s.charAt(i), s.contains(s2), s.endsWith(s2), s.indexOf(s2), s.lastIndexOf(s2), s.length, s.matches(s2), s.replace(s1,s2), s.startsWith(s2), s.substring(i1,i2), s.substring(i), s.toLowerCase, s.toUpperCase, s.trim.

-wayne

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

Re: Using a function that returns a string in the str.*() functions fails

Stein Rørvik
Thanks!

Stein

-----Original Message-----
Sent: 12. mars 2021 19:47
Subject: Re: Using a function that returns a string in the str.*() functions fails

> On Mar 8, 2021, at 10:35 AM, Stein Rørvik <[hidden email]> wrote:
>
> There seems to be a glitch in the macro parser when trying to use a function that returns a string as input in the str.*() functions:
>
> The following fails:
>
> run("Blobs (25K)");
> if (getTitle().contains("blobs")) showMessage("this is the blobs image");
>
> run("Blobs (25K)");
> if (getTitle().endsWith("gif")) showMessage("this is a GIF image");

This bug is fixed in the 1.53i29 daily build.

> Another thing: It would be useful if it was mentioned in the macro functions documentation what version number these useful str.*() functions were introduced, so that one can insert the appropriate requires() statement before using them in a macro.

I updated the documentation for the str.*() functions, under "String Functions" in the Macro Functions list, so it mentions the version of ImageJ required.

These string functions, where 's' is a string variable, are also available in ImageJ 1.52t and newer: s.charAt(i), s.contains(s2), s.endsWith(s2), s.indexOf(s2), s.lastIndexOf(s2), s.length, s.matches(s2), s.replace(s1,s2), s.startsWith(s2), s.substring(i1,i2), s.substring(i), s.toLowerCase, s.toUpperCase, s.trim.

-wayne

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C3085f426b68246e1df0408d8e58777eb%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637511717298830727%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=aswIyusu70U%2FCwg0Kzb%2FBLjA2XcRqzrMpf5ETrlZ3cY%3D&amp;reserved=0

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