Replace part of string help

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

Replace part of string help

Dr Adam Cliffe
Hi,

I'm trying to remove part of a file name.
Current file name is : "Job(Seq.Scan) 2 02_024_z0_ch01.tif"
I'd like to remove the (Seq.Scan) part.

using the following macro I end up with: Job() 2 02_024_z0_ch01.tif

name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";
string=replace(name,"(Seq.Scan)","");
print(name);

Can anyone help getting rid of the brackets please?

thanks

Adam


Dr Adam Cliffe
Research Scientist, Rorth Lab

Institute of Molecular and Cell Biology
61 Biopolis Drive
Proteos
Singapore 138673

tel: +65 6586 9731
Reply | Threaded
Open this post in threaded view
|

Re: Replace part of string help

Julien Colombelli
Hi Adam,

very manual but it works:

name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";

string1= substring(name, 0,3);
string2= substring(name, 13,34);

print(string1+string2);

For sure there's a more elegant solution

cheers,
J


On 28 July 2011 12:22, Dr Adam Cliffe <[hidden email]> wrote:

> Hi,
>
> I'm trying to remove part of a file name.
> Current file name is : "Job(Seq.Scan) 2 02_024_z0_ch01.tif"
> I'd like to remove the (Seq.Scan) part.
>
> using the following macro I end up with: Job() 2 02_024_z0_ch01.tif
>
> name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";
> string=replace(name,"(Seq.Scan)","");
> print(name);
>
> Can anyone help getting rid of the brackets please?
>
> thanks
>
> Adam
>
>
> Dr Adam Cliffe
> Research Scientist, Rorth Lab
>
> Institute of Molecular and Cell Biology
> 61 Biopolis Drive
> Proteos
> Singapore 138673
>
> tel: +65 6586 9731
>



--
Julien Colombelli
Advanced Digital Microscopy
Institute for Research in Biomedicine - IRB Barcelona
Baldiri Reixac, 10
Tel:  +349340-20451
Fax: +34934031116
E-08028 Barcelona - Spain
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Replace part of string help

dscho
In reply to this post by Dr Adam Cliffe
Hi,

On Thu, 28 Jul 2011, Dr Adam Cliffe wrote:

> I'm trying to remove part of a file name.
> Current file name is : "Job(Seq.Scan) 2 02_024_z0_ch01.tif"
> I'd like to remove the (Seq.Scan) part.
>
> using the following macro I end up with: Job() 2 02_024_z0_ch01.tif
>
> name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";
> string=replace(name,"(Seq.Scan)","");

replace() takes a regular expression so parentheses are special. Try
"\\(Seq.Scan\\)" instead.

> print(name);

Maybe print(string)?

Ciao,
Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Replace part of string help

Lim Soon Yew
In reply to this post by Julien Colombelli
Hi Adam,

From Julien code, I added in parts to determine the index positions.

name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";
unwanted_part="(Seq.Scan)";
len1=lengthOf(name);
len2=lengthOf(unwanted_part);
len3=indexOf(name,unwanted_part);
string1=substring(name, len2+len3,len1);
string2=substring(name, 0,len3);
string=string2+string1;
print(string);

Best Regards,
John

________________________________________
From: ImageJ Interest Group [[hidden email]] On Behalf Of Julien Colombelli [[hidden email]]
Sent: Thursday, July 28, 2011 6:35 PM
To: [hidden email]
Subject: Re: Replace part of string help

Hi Adam,

very manual but it works:

name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";

string1= substring(name, 0,3);
string2= substring(name, 13,34);

print(string1+string2);

For sure there's a more elegant solution

cheers,
J


On 28 July 2011 12:22, Dr Adam Cliffe <[hidden email]> wrote:

> Hi,
>
> I'm trying to remove part of a file name.
> Current file name is : "Job(Seq.Scan) 2 02_024_z0_ch01.tif"
> I'd like to remove the (Seq.Scan) part.
>
> using the following macro I end up with: Job() 2 02_024_z0_ch01.tif
>
> name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";
> string=replace(name,"(Seq.Scan)","");
> print(name);
>
> Can anyone help getting rid of the brackets please?
>
> thanks
>
> Adam
>
>
> Dr Adam Cliffe
> Research Scientist, Rorth Lab
>
> Institute of Molecular and Cell Biology
> 61 Biopolis Drive
> Proteos
> Singapore 138673
>
> tel: +65 6586 9731
>



--
Julien Colombelli
Advanced Digital Microscopy
Institute for Research in Biomedicine - IRB Barcelona
Baldiri Reixac, 10
Tel:  +349340-20451
Fax: +34934031116
E-08028 Barcelona - Spain
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Replace part of string help

Advrk Aplmrkt
On 28 July 2011 07:03, Lim Soon Yew <[hidden email]> wrote:

> Hi Adam,
>
> From Julien code, I added in parts to determine the index positions.
>
> name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";
> unwanted_part="(Seq.Scan)";
> len1=lengthOf(name);
> len2=lengthOf(unwanted_part);
> len3=indexOf(name,unwanted_part);
> string1=substring(name, len2+len3,len1);
> string2=substring(name, 0,len3);
> string=string2+string1;
> print(string);
>
> Best Regards,
> John
> ________________________________________
> From: ImageJ Interest Group [[hidden email]] On Behalf Of Julien Colombelli [[hidden email]]
> Sent: Thursday, July 28, 2011 6:35 PM
> To: [hidden email]
> Subject: Re: Replace part of string help
>
> Hi Adam,
>
> very manual but it works:
>
> name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";
>
> string1= substring(name, 0,3);
> string2= substring(name, 13,34);
>
> print(string1+string2);
>
> For sure there's a more elegant solution
>
> cheers,
> J
>
> On 28 July 2011 12:22, Dr Adam Cliffe <[hidden email]> wrote:
>
>> Hi,
>>
>> I'm trying to remove part of a file name.
>> Current file name is : "Job(Seq.Scan) 2 02_024_z0_ch01.tif"
>> I'd like to remove the (Seq.Scan) part.
>>
>> using the following macro I end up with: Job() 2 02_024_z0_ch01.tif
>>
>> name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";
>> string=replace(name,"(Seq.Scan)","");
>> print(name);
>>
>> Can anyone help getting rid of the brackets please?
>>
>> thanks
>>
>> Adam

Hello,
Sorry I don't mean to be ignorant and missing something obvious here,
but do you need to do this via a macro in ImageJ?
What about just using batch file rename software such as Metamorphose
2 on Windows (http://file-folder-ren.sourceforge.net/), or an
equivalent on the OS you run?
I've used Metamorphose or Linux shell scripts to batch rename and
process my images, it works great for me.
Reply | Threaded
Open this post in threaded view
|

Re: Replace part of string help

Nathaniel Ryckman
In reply to this post by Dr Adam Cliffe
System.out.print(name.replace("(Seq.Scan)",""));

There is no reason to use regular expressions for something so simple. Also, you could make the replace function from scratch, but why bother when someone has already included that functionality into the String class?

Dr Adam Cliffe wrote
Hi,

I'm trying to remove part of a file name.
Current file name is : "Job(Seq.Scan) 2 02_024_z0_ch01.tif"
I'd like to remove the (Seq.Scan) part.

using the following macro I end up with: Job() 2 02_024_z0_ch01.tif

name = "Job(Seq.Scan) 2 02_024_z0_ch01.tif";
string=replace(name,"(Seq.Scan)","");
print(name);

Can anyone help getting rid of the brackets please?

thanks

Adam


Dr Adam Cliffe
Research Scientist, Rorth Lab

Institute of Molecular and Cell Biology
61 Biopolis Drive
Proteos
Singapore 138673

tel: +65 6586 9731