question about zero values in strings

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

question about zero values in strings

Cammer, Michael
I am opening a metadata file that matches an image file using the following commands in a macro:

  //Open the metadata.
  run("Text File... ", "open=[" + path + t + "]");
  selectWindow(t);

Each line of text looks like this:

A n a l o g   l e v e l   =   7 . 0

as though the are extra spaces in between the characters.  Using the charCodeAt(fulltext, 5) command, however, it appears that the spaces are really zeros.  Therefore, the command

  fulltext = replace(fulltext, ' ', '');

will not get rid of them.  Without having to write a loop to check each character code and recreate the string without the zeros, which I will do if I have to, is there a way to get rid of the zeros?  Full macro so far below if you want to see what we are trying to do in full.

Thank you!

Regards,

Michael

=============
macro "Olympus Metadata extraction [q]" {

  //  Get the unique image identifier so that the image window may be selected again later.
  original = getImageID();

  // Get the path to the directory that the image is stored in.
  path = getDirectory("image");

  //  Get the title of the image.  The metadata file should be this name in the image directory.
  t = getTitle();

  // Switch extension from ".tif" to ".pty"
  t = replace(t, ".tif", ".pty");

  // Check if there really is such a file and exit if there isn't one.
  exists = File.exists(path+t);
  if (exists != 1) exit('There does not seem to be a matching metadata file for '+path+t+'');

  //Open the metadata.
  run("Text File... ", "open=[" + path + t + "]");
  selectWindow(t);


  // Make an array of properties by splitting the text file based on newline and carriage return.
  fulltext =getInfo("window.contents");
  fulltext = replace(fulltext, ' ', '');
  properties = split(fulltext, " \n\r");



} // end



_________________________________________
Michael Cammer, Assistant Research Scientist
Skirball Institute of Biomolecular Medicine
Lab: (212) 263-3208  Cell: (914) 309-3270
------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

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

Re: question about zero values in strings

Cammer, Michael
When I woke up this morning I realized that I had overlooked an obvious way to deal with the Unicode 16 problem.

  remove = fromCharCode(0);
  fulltext = replace(fulltext, remove, '');

Sorry to bother you all.

Regards,

Michael

===========================================================================
Michael Cammer, Microscopy Core & Dustin Lab , Skirball Institute, NYU Langone Medical Center
Cell:  914-309-3270   Lab: 212-263-3208
http://ocs.med.nyu.edu/microscopy & http://www.med.nyu.edu/skirball-lab/dustinlab/

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Cammer, Michael
Sent: Sunday, May 04, 2014 3:13 PM
To: [hidden email]
Subject: question about zero values in strings

I am opening a metadata file that matches an image file using the following commands in a macro:

  //Open the metadata.
  run("Text File... ", "open=[" + path + t + "]");
  selectWindow(t);

Each line of text looks like this:

A n a l o g   l e v e l   =   7 . 0

as though the are extra spaces in between the characters.  Using the charCodeAt(fulltext, 5) command, however, it appears that the spaces are really zeros.  Therefore, the command

  fulltext = replace(fulltext, ' ', '');

will not get rid of them.  Without having to write a loop to check each character code and recreate the string without the zeros, which I will do if I have to, is there a way to get rid of the zeros?  Full macro so far below if you want to see what we are trying to do in full.

Thank you!

Regards,

Michael

=============
macro "Olympus Metadata extraction [q]" {

  //  Get the unique image identifier so that the image window may be selected again later.
  original = getImageID();

  // Get the path to the directory that the image is stored in.
  path = getDirectory("image");

  //  Get the title of the image.  The metadata file should be this name in the image directory.
  t = getTitle();

  // Switch extension from ".tif" to ".pty"
  t = replace(t, ".tif", ".pty");

  // Check if there really is such a file and exit if there isn't one.
  exists = File.exists(path+t);
  if (exists != 1) exit('There does not seem to be a matching metadata file for '+path+t+'');

  //Open the metadata.
  run("Text File... ", "open=[" + path + t + "]");
  selectWindow(t);


  // Make an array of properties by splitting the text file based on newline and carriage return.
  fulltext =getInfo("window.contents");
  fulltext = replace(fulltext, ' ', '');
  properties = split(fulltext, " \n\r");



} // end



_________________________________________
Michael Cammer, Assistant Research Scientist Skirball Institute of Biomolecular Medicine
Lab: (212) 263-3208  Cell: (914) 309-3270
------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

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

------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

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