2 Replies Latest reply: Oct 3, 2008 4:09 PM by DrClap RSS

    Question abotu String.format() functionality

      Hello all,

      I am curious as to whether this functionality exists in the String.format method, or if there is any other class in the current version of Java that would allow for this.

      I want to construct a format string, where if one of the args contains a newline character in it, the same format for that arg will be used on the newline.

      String s = String.format("%20s%20s","this line contains\na newline character","so does\nthis one");
      Actual Output:
      this line contains
      a newline character    so does
      this one
      Wanted Output:
      this line contains         so does
      a newline character      this one
      Hopefully there is something that exisits in the language that would allow me to do this. If no one can think of any easy way to do this? I have a few ideas, but it would require a whole lot of string manip. than I want to put into it =(

      Anyways, I look forward to your reply. Thanks!