This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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: 7892
    
  21

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
 
GeeCON Prague 2014
 
subject: Find and replace a pattern in a String