문제

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