File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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: 8008
    
  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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Find and replace a pattern in a String