how to extract data from the filename using string operations ?

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

how to extract data from the filename using string operations ?

nckrzan
Hi,

First I would like to thanks all friends, who help me during last days
with my problems. My Macro is already grate!. Thanks only for You...


Now I start to work with probably last problem.

In my research the few important parameters varied between different
experiments. Therefore I always recorded them during the  save operation
for AVI files.

The names of my files looks like:

c12dmpo_1e5M_cal356_capM1_100Hz_00_5.avi

It will be super if my Macro can automaic extract the 3 most important
parameter from the filename

cal356 - 356 it's the calibration value, I need in in the integer
capM1 - M1 - number of my capillary - it can be a string
100Hz - 100 - frequency of the stroboscopic illumination

As You see, the two parameters should be also convert for the integer ...

Best regards,

Marcel Krzan





___ The message was checked by EMS.___
Reply | Threaded
Open this post in threaded view
|

Re: how to extract data from the filename using string operations ?

Michael Schmid
Hi Marcel,

look at the string manipulation functions in the macro language. Here  
is an example:

name="c12dmpo_1e5M_cal356_capM1_100Hz_00_5.avi";
calString = getSubstring(name, "_cal", "_");
calValue = NaN; //or whatever to tell you that you could not read the  
value
if(calString!="")
   calValue=parseInt(calString); //parseFloat if not always an  
integer value
print (calValue);

function getSubstring(string, prefix, postfix) {
   start=indexOf(name, prefix)+lengthOf(prefix);
   end=start+indexOf(substring(name, start), postfix);
   if(start>=0&&end>=0)
     return substring(name, start, end);
   else
     return "";
}

You can use the same for prefix="_cap" and with no parseInt for the  
cap String.
For the "100 Hz" it is more difficult. If this is always directly  
after the '_cap' item, use something like
capIndex = indexOf(name,"_cap");
afterCap = substring(name, capIndex+3);
hzString = getSubstring(afterCap, "_", "Hz");

Otherwise, you have to get IndexOf(name, "Hz_") and run a 'for' loop  
from this value to 0, extracting character by character (see  
'charCodeAt') and see whether it matches an underscore. Then extract  
the substring between these two positions.

Much fun with all the String dissecting!

Michael
________________________________________________________________

On 16 Aug 2011, at 19:21, Marcel Krzan wrote:

> Hi,
>
> First I would like to thanks all friends, who help me during last days
> with my problems. My Macro is already grate!. Thanks only for You...
>
>
> Now I start to work with probably last problem.
>
> In my research the few important parameters varied between different
> experiments. Therefore I always recorded them during the  save  
> operation
> for AVI files.
>
> The names of my files looks like:
>
> c12dmpo_1e5M_cal356_capM1_100Hz_00_5.avi
>
> It will be super if my Macro can automaic extract the 3 most important
> parameter from the filename
>
> cal356 - 356 it's the calibration value, I need in in the integer
> capM1 - M1 - number of my capillary - it can be a string
> 100Hz - 100 - frequency of the stroboscopic illumination
>
> As You see, the two parameters should be also convert for the  
> integer ...
>
> Best regards,
>
> Marcel Krzan