Hi everyone!!!
I'm learning imagej Macro programming and need help with an issue regarding the Built-in Macro Function: replace(string, old, new). Whenever I want to replace a string containing "*None*", it wouldn't work. Does anybody know what's going on? I send you an example. string0 = "red=*None* green=*None* blue=*None* gray=*None*"; print("string0:"+string0); string1 = replace(string0, "red=*None*", "red=Ejemplo.tif-Red"); print("string1: "+string1); Thank you very much in advance. Joaquim Soriano Felipe. Confocal Microscopy Unit Spanish National Cancer Research Centre (CNIO) Melchor Fernández Almagro,3, E-28029 Madrid, Spain Phone + 34 917 328 000, exts.: 3161, 3162. [hidden email]<mailto:[hidden email]> |
On Monday 13 Jun 2011 14:51:45 you wrote:
> Hi everyone!!! > I'm learning imagej Macro programming and need help with an issue regarding > the Built-in Macro Function: replace(string, old, new). Whenever I want to > replace a string containing "*None*", it wouldn't work. Does anybody know > what's going on? > I send you an example. > > string0 = "red=*None* green=*None* blue=*None* gray=*None*"; > print("string0:"+string0); > string1 = replace(string0, "red=*None*", "red=Ejemplo.tif-Red"); > print("string1: "+string1); You need to check the Regular Expressions link in the IJ site associated with "replace". This seems to work: string0 = "red=*None* green=*None* blue=*None* gray=*None*"; print("string0:"+string0); string1 = replace(string0, "red=\\*None\\*", "red=Ejemplo.tif-Red"); print("string1: "+string1); Cheers Gabriel |
In reply to this post by Soriano.Joaquim
Hello Joaquim,
You need to scape asterisks by using "\\*". Your code will be something like this: > string0 = "red=*None* green=*None* blue=*None* gray=*None*"; > print("string0:"+string0); > string1 = replace(string0, "red=\\*None\\*", "red=Ejemplo.tif-Red"); > print("string1: "+string1); You will obtain the following as output: string0:red=*None* green=*None* blue=*None* gray=*None* string1: red=Ejemplo.tif-Red green=*None* blue=*None* gray=*None* Hope that helps! Sincerely, Juanjo. On Jun 13, 2011, at 3:51 PM, Soriano.Joaquim wrote: > Hi everyone!!! > I'm learning imagej Macro programming and need help with an issue regarding the Built-in Macro Function: replace(string, old, new). > Whenever I want to replace a string containing "*None*", it wouldn't work. > Does anybody know what's going on? > I send you an example. > > string0 = "red=*None* green=*None* blue=*None* gray=*None*"; > print("string0:"+string0); > string1 = replace(string0, "red=*None*", "red=Ejemplo.tif-Red"); > print("string1: "+string1); > > Thank you very much in advance. > > Joaquim Soriano Felipe. > Confocal Microscopy Unit > Spanish National Cancer Research Centre (CNIO) > Melchor Fernández Almagro,3, E-28029 Madrid, Spain > Phone + 34 917 328 000, exts.: 3161, 3162. [hidden email]<mailto:[hidden email]> ------------------------------------------------------------ Juanjo Vega ([hidden email]) Unidad de Biocomputación. Laboratorio B-13. Centro Nacional de Biotecnología. CNB-CSIC. C\ Darwin, 3. Campus de Cantoblanco. Universidad Autónoma de Madrid. 28049, Madrid, Spain. http://www.cnb.csic.es http://www.biocomp.cnb.csic.es +34 91 585 4510 "Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes. |
Free forum by Nabble | Edit this page |