0

imageName=getTitle(); #This returns a string with the entire path of where the image is.

image1 = split(imageName,"/"); #splits the image where "/" is. Based on path, this varies in length

image = image1[1]; #I want the last one but it will not always be the nth index.

Karina
  • 33
  • 5

2 Answers2

1

split() returns an array. In your example you assign the array to image1 so you can find the length of the array using image1.length. Arrays in ImageJ macro language are 0-based so you need to subtract 1 to find the last element.

imageName=getTitle(); #This returns a string with the entire path of where the image is.
image1 = split(imageName,"/"); #splits the image where "/" is. Based on path, this varies in length
image = image1[image1.length - 1]; #last element.

Note that splitting using / will work on mac but not Windows.

My answer is directed at your indexing question. If you simply want the file name without the path, Take a look at File.name and File.nameWithoutExtension for more straightforward ways to get what you need.

quantixed
  • 287
  • 3
  • 12
0

You write: "imageName=getTitle(); #This returns a string with the entire path of where the image is."

This isn't true. "getTitle();" returns the name of the frontmost image including its suffix, not the path!

Herbie
  • 143
  • 5