wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Find and replace a pattern in a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Find and replace a pattern in a String" Watch "Find and replace a pattern in a String" New topic
Author

Find and replace a pattern in a String

Aditya Sirohi
Ranch Hand

Joined: Jan 05, 2010
Posts: 93

Hello,


I want to replace "|DEPLOYDIR|" expression in the string test.

String test = "cmd /c start /wait |DEPLOYDIR|\\setup";
test = test.replaceAll("|^DEPLOYDIR|$", "testvalue"); --> does not seem to work!!

I want an output like:
cmd /c start /wait testvalue\\setup

How can i do this??

-Adi
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8043
    
  22

Aditya Sirohi wrote:I want an output like:
cmd /c start /wait testvalue\\setup
How can i do this??

Did you try
test = test.replace("|DEPLOYDIR|", "testvalue");
?

Sometimes you can overthink things

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Find and replace a pattern in a String