Re: find number in a string
Posted by
Wayne Rasband on
URL: http://imagej.273.s1.nabble.com/find-number-in-a-string-tp3701189p3701190.html
> 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