Login  Register

Re: s.replace question

Posted by Cammer, Michael-3 on Aug 11, 2020; 9:08pm
URL: http://imagej.273.s1.nabble.com/s-replace-question-tp5023836p5023837.html

Sorry I left out that before trying to remove the parentheses, there is the following code:


i = 27;
newTitle = getMetadata("Label");
print("\nOriginal:  " + newTitle);
newTitle = newTitle.replace("c:3/3 - ", "");
newTitle = newTitle.replace(".nd2", "");
newTitle = newTitle.replace("series 1", "");


________________________________
From: Cammer, Michael <[hidden email]>
Sent: Tuesday, August 11, 2020 5:05:56 PM
To: [hidden email]
Subject: s.replace question

[EXTERNAL]

I have been trying to remove parentheses from a string using the s.replace command and have been getting strange results.  (Practically, I was able to solve the problem by cutting the string apart, trimming out the parentheses and reassembling the string, but am asking specifically about the s.replace behavior.)


Code such as this

newTitle = newTitle.replace("(", "");

returns an error message.


Therefore, I tried setting a variable to "()" and used the following syntax:

print("Before trying to replace parentheses:  " + newTitle);
parentheses = fromCharCode(40, 41);
print(parentheses);
newTitle = newTitle.replace(parentheses, "");
newTitle = newTitle + IJ.pad(i, 3);
print("Processed:  " + newTitle);
with output that does not remove the parentheses:

Original:  c:3/3 - KO_1 nM_rep2_007.nd2 (series 1)
Before trying to replace parentheses:  KO_1 nM_rep2_007 ()
()
Processed:  KO_1 nM_rep2_007 ()027

And odder, the output in this case inserts "xx" between every character:


print("Before trying to replace parentheses:  " + newTitle);
parentheses = fromCharCode(40, 41);
print(parentheses);
newTitle = newTitle.replace(parentheses, "xx");
newTitle = newTitle + IJ.pad(i, 3);
print("Processed:  " + newTitle);



Original:  c:3/3 - KO_1 nM_rep2_007.nd2 (series 1)
Before trying to replace parentheses:  KO_1 nM_rep2_007 ()
()
Processed:  xxKxxOxx_xx1xx xxnxxMxx_xxrxxexxpxx2xx_xx0xx0xx7xx xx(xx)xx027



Any ideas?


Thank you!


Michael Cammer, Sr Research Scientist, DART Microscopy Laboratory

NYU Langone Health, 540 First Avenue, SK2 Microscopy Suite, New York, NY  10016

[hidden email]<mailto:[hidden email]>  https://urldefense.proofpoint.com/v2/url?u=http-3A__nyulmc.org_micros&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=E0xNnPAQpUbDiPlC50tp7rW2nBkvV7fujQf0RknE5bU&m=2rgsSf1b19Xe2HaA9-8saPs1zuKolzRHaBlzt84sxtY&s=WL9zhPlv6pElXz3GCVJj0nYhuaIxKWC-b9vbI0iMrZc&e=   https://urldefense.proofpoint.com/v2/url?u=http-3A__microscopynotes.com_&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=E0xNnPAQpUbDiPlC50tp7rW2nBkvV7fujQf0RknE5bU&m=2rgsSf1b19Xe2HaA9-8saPs1zuKolzRHaBlzt84sxtY&s=wOP7EA9iAuKgLu-oT_P201QJl0TAOG_eXP9nFQhqmjM&e=

Voice direct only, no text or messages:  1-914-309-3270 and 1-646-501-0567


--
ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedeElZfc04rx3ExJHeIIZuCs&r=E0xNnPAQpUbDiPlC50tp7rW2nBkvV7fujQf0RknE5bU&m=2rgsSf1b19Xe2HaA9-8saPs1zuKolzRHaBlzt84sxtY&s=38Mrki7TDUGWBUKrPoDsDw7lCrX1D8kH0lxy8bqCezk&e=

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