質問

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.

役に立ちましたか?

解決

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top