Format a message using MessageFormat.format() in Java

前端 未结 6 504
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 18:58

I have stored some messages in a resource bundle. I\'m trying to format these messages as follows.

import java.text.MessageFormat;

String text = MessageForm         


        
6条回答
  •  既然无缘
    2020-12-04 19:25

    Here is a method that does not require editing the code and works regardless of the number of characters.

    String text = 
      java.text.MessageFormat.format(
        "You're about to delete {0} rows.".replaceAll("'", "''"), 5);
    

提交回复
热议问题