Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1205079

string.trim() doesn't trim trailing white space.

XMLWordPrintable

    • 1.0beta
    • sparc
    • solaris_2.5
    • Not verified

      This program:

      class Main {
          public static void main (String args[]) {

      String one = "no white space";
      String two = " leading white space";
      String three = "trailing white space ";
      String four = " leading and trailing white space ";
      System.out.println("\\"" + one.trim() + "\\"");
      System.out.println("\\"" + two.trim() + "\\"");
      System.out.println("\\"" + three.trim() + "\\"");
      System.out.println("\\"" + four.trim() + "\\"");
          }
      }


      yields this output:

      "no white space"
      "leading white space"
      "trailing white space "
      "leading and trailing white space "

      Note that the trailing white space on the last two lines of output has not been trimmed.

      fy-
      I'll take this one. It's a trivial bug, and I'm looking at String.java anyway. . ..

            fyellinsunw Frank Yellin (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: