find number in a string

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

find number in a string

roberto aranibar
Dear ImageJ users,

Does anyone know an easy way to find a 1 to 4 digit number (unknown) within
an ROI name? I have this so far:

requires("1.37q")
for(index=0; index<roiManager("count"); index++) {
name=call("ij.plugin.frame.RoiManager.getName",index);
iFirst=indexOf(name,####);
iLast=lastIndexOf(name,####);
number=substring(name,iFirst,iLast);
}

Thanks in advance for any help/ideas anyone can offer?

Roberto

_________________________________________________________________
All-in-one security and maintenance for your PC.  Get a free 90-day trial!
http://clk.atdmt.com/MSN/go/msnnkwlo0050000002msn/direct/01/?href=http://www.windowsonecare.com/?sc_cid=msn_hotmail
Reply | Threaded
Open this post in threaded view
|

Re: find number in a string

Wayne Rasband
> Dear ImageJ users,
>
> Does anyone know an easy way to find a 1 to 4 digit number  
> (unknown) within an ROI name? I have this so far:
>
> requires("1.37q")
> for(index=0; index<roiManager("count"); index++) {
> name=call("ij.plugin.frame.RoiManager.getName",index);
> iFirst=indexOf(name,####);
> iLast=lastIndexOf(name,####);
> number=substring(name,iFirst,iLast);
> }
>
> Thanks in advance for any help/ideas anyone can offer?

    n = "";
    for (i=0; i<lengthOf(name); i++) {
        c = substring(name, i, i+1);
        if (c>="0" && c<="9")
            n = n + c;
    }
    n = parseInt(n);

-wayne