string macro functions

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

string macro functions

Leoncio Vergara
Hi

A very basic question: how do I use these string functions?

These string functions, where 's' is a string variable, are also available: 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.

they are mentioned in the built in macro functions list, but I couldn't figure to make them work. I get an error message.

for example for  s.charAt(i), I tried the following:

ID="A09";
X=ID.charAt(1);
print(X);

thinking it would print "A" or "0"... but nope...

Thanks for your help.

Leo V.

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

Re: string macro functions

Straub, Volko A. (Dr.)
Hi Leo,

Substring should do what you want. Try this:
ID="A09";
X=substring(ID,0,1);
print(X);

Cheers,
Volko



-----Original Message-----
From: Leoncio Vergara <[hidden email]>
Sent: 18 November 2020 02:10
To: [hidden email]
Subject: string macro functions

Hi

A very basic question: how do I use these string functions?

These string functions, where 's' is a string variable, are also available: 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.

they are mentioned in the built in macro functions list, but I couldn't figure to make them work. I get an error message.

for example for  s.charAt(i), I tried the following:

ID="A09";
X=ID.charAt(1);
print(X);

thinking it would print "A" or "0"... but nope...

Thanks for your help.

Leo V.

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cvs64%40leicester.ac.uk%7C048d7ed8f5764bda387908d88b671ac8%7Caebecd6a31d44b0195ce8274afe853d9%7C0%7C1%7C637412622243719666%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=8elaNPu8wLV2sjA5iyM6QxIRqOfGuyn%2BNfDvH7lQqwI%3D&amp;reserved=0

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

Re: string macro functions

Gabriel Landini
In reply to this post by Leoncio Vergara
On Wednesday, 18 November 2020 02:09:32 GMT you wrote:
> ID="A09";
> X=ID.charAt(1);
> print(X);

That macro returns "0" in my installation v1.53g15, which is the expected
value: the character at position 1 of the ID string is a "0".

And  X=ID.charAt(0);  returns "A"
Cheers

Gabriel

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

Re: string macro functions

Herbie
In reply to this post by Leoncio Vergara
Greetings,

the macro

/////////////////
requires("1.53f")
ID="A09";
X=ID.charAt(0);
print(X);
X=ID.charAt(1);
print(X);
X=ID.charAt(2);
print(X);
/////////////////

nicely returns

A
0
9

Regards

Herbie

:::::::::::::::::::::::::::::::::::::::::::::
Am 18.11.20 um 03:09 schrieb Leoncio Vergara:

> Hi
>
> A very basic question: how do I use these string functions?
>
> These string functions, where 's' is a string variable, are also available: 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.
>
> they are mentioned in the built in macro functions list, but I couldn't figure to make them work. I get an error message.
>
> for example for  s.charAt(i), I tried the following:
>
> ID="A09";
> X=ID.charAt(1);
> print(X);
>
> thinking it would print "A" or "0"... but nope...
>
> Thanks for your help.
>
> Leo V.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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