sprintf这个东东忘了是什么了,能说说吗?

解决方案 »

  1.   

    构造字符串的,比如sprintf("abc%s123","def");会生成一个字符串abcdef123;
    跟printf()差不多的规则
      

  2.   

    好象明白了,不过好象没有什么用啊,自己写个类倒可以实现,至于JAVA本身有没有就不清楚了
      

  3.   

    谢谢几位了,也不是一定不用+
    只是一个文书打印,已经定义好了格式,有些位置要填数据(几十项,要用+的话偶觉得很麻烦:)
    刚写了一个简单的,凑和着用,有bug或效率问题欢迎指出,都有分:)
      public static String replace(String source,String[] args)
      {
        //if(source == null || args == null ||(args.length != source.
        int start = 0;
        StringBuffer buffer = new StringBuffer(source);
        for(int i=0;i<args.length;i++)
        {
          int postion = source.indexOf("%",start);
          if((postion == -1) || ((postion+1) == source.length()))
          {
            break;
          }
          switch(source.charAt(postion + 1))
          {
            case 's':
              buffer.delete(postion,postion + 2);
              buffer.insert(postion,args[i]);
              break;
          }
          start = postion + args[i].length();
          source = buffer.toString();
        }
        return source;
      }
      public static void main(String[] args)
      {
        System.out.println(replace("abc%s%s123%s",new String[]{"abc","cde","slfjslf"}));
        System.out.println();
      }
      

  4.   

    在Java中,你可以用System.out.xxx()产生输出。