当前位置:   article > 正文

替换{0}为指定的字符串(MessageFormat)

替换字符串中{0}
 1 package com.text;  
 2   
 3 import java.text.MessageFormat;  
 4   
 5 /**替换{0}为指定的字符串*/  
 6 public class MessageFormatTest {  
 7     public static void main(String[] args) {  
 8         String message = "hello {0}{1}";  
 9         message  =  MessageFormat.format(message ,"world","!!!");  
10         System.out.println(message);  
11     }  
12 }  

 

  1. <script type="text/javascript">
  2. String.prototype.format=function()
  3. {
  4. if(arguments.length==0) return this;
  5. for(var s=this, i=0; i<arguments.length; i++)
  6. s=s.replace(new RegExp("\\{"+i+"\\}","g"), arguments[i]);
  7. return s;
  8. };
  9. alert("js实现用自符串替换占位符{0} {1} {2}".format("I", "LOVE", "YOU"));
  10. </script>

  

转载于:https://www.cnblogs.com/cxxjohnson/p/8504267.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/829801
推荐阅读
相关标签
  

闽ICP备14008679号