Login  Register

Re: String Manipulation in Macros

Posted by Michael Schmid on Aug 17, 2009; 8:20am
URL: http://imagej.273.s1.nabble.com/String-Manipulation-in-Macros-tp3691475p3691477.html

Hi,

when a string argument contains spaces, don't forget to put square  
brackets around it:

saveAs("Tiff", "["+path.substring(0,path.length()-4)+" - green.tif]");

Michael
________________________________________________________________

On 16 Aug 2009, at 03:34, Ben Tupper wrote:

> Hi,
>
> Check out...
> http://rsb.info.nih.gov/ij/developer/macro/macros.html#strings
>
> I think the following does as you ask.
>
> filename = "/Users/Shared/data/cruise/KN193/examples/ciliate.csv";
> //saveAs("Tiff", path.substring(0,path.length()-4)+" - green.tif");
> newname = substring(filename, 0, lengthOf(filename)-4) + "-green.csv";
> print(newname);
>
>
> Cheers,
> Ben
>
> On Aug 15, 2009, at 1:13 PM, ptandon0 wrote:
>
>> Hi,
>>
>> I'm using the BatchProcessFolders.txt macro included with imageJ  
>> to split
>> channels of 16 bit images. I need to modify the filenames to save the
>> results.
>>
>> The full filename is passed to function processFile(String path) as a
>> string, but i would like to modify this String to change the  
>> filename,
>> something like:
>>
>> saveAs("Tiff", path.substring(0,path.length()-4)+" - green.tif");
>>
>> But the macro doesn't seem to have access to String methods, and  
>> returns the
>> error "length expected in line 45."
>>
>> Anyone know a way around this?
>>
>> Using ImageJ 1.42q.
>>
>>> ptandon
>> --
>> View this message in context: http://n2.nabble.com/String- 
>> Manipulation-in-Macros-tp3450486p3450486.html
>> Sent from the ImageJ mailing list archive at Nabble.com.
>
> Ben Tupper