Make an escaped string in IJ macro language

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

Make an escaped string in IJ macro language

lechristophe
Hi,

I'm trying to make a properly escaped string from a non-escaped Windows
path string, i.e.

from
C:\Users\christo\161212(test ABL b2s)\Locs\
to
C:\\Users\\christo\\161212(test ABL b2s)\\Locs\\

however both
replace(path, "\\", "\\\\")
and
replace(path, "\\", File.separator+File.separator)
throw a regex error.

How should I devise the replacement string "\\" to be handled by the
"replace" macro function?

Thanks,

Christophe

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Make an escaped string in IJ macro language

lechristophe
I did it with this ugly thing :

function escapePath(p) {
if (indexOf(p, "\\") > 0) {
pE = split(p, "\\");
pF = ""+ pE[0] + "\\" + "\\";
for (i = 1; i < pE.length; i++) {
pF = pF + pE[i] + "\\" + "\\";
}
}
else {
pF = p;
}
print(pF);
return pF;
}


but a proper replacement string would be nicer (could never wrap my head
around regex syntax)

Christophe

On Tue, Dec 13, 2016 at 12:12 PM, Christophe Leterrier <
[hidden email]> wrote:

> Hi,
>
> I'm trying to make a properly escaped string from a non-escaped Windows
> path string, i.e.
>
> from
> C:\Users\christo\161212(test ABL b2s)\Locs\
> to
> C:\\Users\\christo\\161212(test ABL b2s)\\Locs\\
>
> however both
> replace(path, "\\", "\\\\")
> and
> replace(path, "\\", File.separator+File.separator)
> throw a regex error.
>
> How should I devise the replacement string "\\" to be handled by the
> "replace" macro function?
>
> Thanks,
>
> Christophe
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Make an escaped string in IJ macro language

Kota Miura
Hi Christophe,

More backslashes!

path = "C:\\Users\\christo\\161212(test ABL b2s)\\Locs\\";
print("before", path);
path2 = replace(path, "\\\\", "\\\\\\\\");
print("after", path2);

On Tue, Dec 13, 2016 at 12:40 PM, Christophe Leterrier <
[hidden email]> wrote:

> I did it with this ugly thing :
>
> function escapePath(p) {
> if (indexOf(p, "\\") > 0) {
> pE = split(p, "\\");
> pF = ""+ pE[0] + "\\" + "\\";
> for (i = 1; i < pE.length; i++) {
> pF = pF + pE[i] + "\\" + "\\";
> }
> }
> else {
> pF = p;
> }
> print(pF);
> return pF;
> }
>
>
> but a proper replacement string would be nicer (could never wrap my head
> around regex syntax)
>
> Christophe
>
> On Tue, Dec 13, 2016 at 12:12 PM, Christophe Leterrier <
> [hidden email]> wrote:
>
> > Hi,
> >
> > I'm trying to make a properly escaped string from a non-escaped Windows
> > path string, i.e.
> >
> > from
> > C:\Users\christo\161212(test ABL b2s)\Locs\
> > to
> > C:\\Users\\christo\\161212(test ABL b2s)\\Locs\\
> >
> > however both
> > replace(path, "\\", "\\\\")
> > and
> > replace(path, "\\", File.separator+File.separator)
> > throw a regex error.
> >
> > How should I devise the replacement string "\\" to be handled by the
> > "replace" macro function?
> >
> > Thanks,
> >
> > Christophe
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>



--

-------------------------------------------------------------
Dr. Kota Miura <[hidden email]>

Freelance Image Analyst
Mobile +49 160 95001177http://wiki.cmci.info
++++++++++++++++++

Nikon Imaging Center, Visiting Image Analyst
Bioquant BQ 0004
Im Neuenheimer Feld 267
69120 Heidelberg

Research Collaboration Fellow
National Institute of Basic Biology
Okazaki, 444-8585
JAPAN

++++++++++++++++++


-------------------------------------------------------------

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html