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

split(String regex) doesn't work with regex="|" (or = "\u007c")

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      Netbeans 4.0 internal enviroment

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP Professional
      Versione 2002
      Service Pack 1

      A DESCRIPTION OF THE PROBLEM :
      The following java code:
      str.split("|");
      str.split("\u007c");
      they both split the str string in a wrong way.
      Instead of splitting the str for each "|" char,
      the str is splitted in strings of one char each.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this piece of code:
      String str = "first|second";
      String[] strArray = str.split("|");
      for(int ii=0;ii<strArray.length;ii++)
         System.out.println(strArray[ii]);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Output:
      first
      second
      ACTUAL -
      Output:
      f
      i
      r
      s
      t
      |
      s
      e
      c
      o
      n
      d


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      String str = "first|second";
      String[] strArray = str.split("|");
      for(int ii=0;ii<strArray.length;ii++)
         System.out.println(strArray[ii]);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      if the str string does not contain the ";"
      you can substitute the str.split("|");
      with str.replace('|', ';').split(";");
      ###@###.### 2005-04-12 08:54:27 GMT

            martin Martin Buchholz
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: