Question

I am running in to bit of a trouble trying to use parametric replacement.

In my properties file I have the following entry

tpi.message=This is a test message. Generated for ? on ? .

The text above is displayed on the web and in the report therefore I need to replace ? with parameters.

However, I can't use replace* method because ? is special character for regex. I also don't want to use String.format method.

I know it is possible to replace ? but I don't remember how.

Your help is appreciated.

Was it helpful?

Solution

You can do it like this:

String message = "This is a test message. Generated for ? on ?";
message = message.replaceFirst("\\?", "Bob").replaceFirst("\\?", "Tuesday");
System.out.println(message);  // This is a test message. Generated for Bob on Tuesday
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top