• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Find and replace a pattern in a String

 
Aditya Sirohi
Ranch Hand
Posts: 93
Eclipse IDE Linux VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 9442
49
Eclipse IDE Hibernate Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic