Problem with String.split(Regex arg)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Blue Ocean

    Problem with String.split(Regex arg)

    In short, it's not working right for me.

    In long:

    The program is designed to read numbers from an accumulator and speak
    them out loud. Unfortunately, the class that contains the method to
    read off large numbers is only for integers. My intention is to split
    a String across the Regex of ".". However, this code does not work:

    private void doRealValueOf(S tring text) {
    BBI beforeDot, afterDot;
    String decArray[];

    decArray = text.split(".", 2);

    beforeDot = new BBI(decArray[0]);
    afterDot = new BBI(decArray[1]);

    beforeDot.play( );
    playString("poi nt.au");
    sleep(400);
    afterDot.play() ;
    }

    Please assume as your read that all of the called methods except
    text.split(".") works.

    I can _guarantee_ by use of a debugger that text does not have the
    regex in more than one place. In my test case, "4.0", the output of
    text.split(".") is

    text.split(".")
    (java.lang.Stri ng[]) []

    I really cannot fathom why this might be the case.

    For reference, the output of the two argument split methods are as
    follows:

    text.split(".", 0)
    (java.lang.Stri ng[]) []
    text.split(".", 1)
    (java.lang.Stri ng[]) [4.0]
    text.split(".", 2)
    (java.lang.Stri ng[]) [, .0]

    And calling the toString method on the String text:

    text
    (java.lang.Stri ng) 4.0

    These are all from the _exact same instant_ of the virtual machine;
    the thread that all these variables are in is suspended, so there is
    no chance of something being incorrect due to changes in the state of
    the locals.

    Please help me. I'm starting to get desperate. I've been working on
    this one problem for more than two hours now, and it is my only
    roadblock to success. Anyone who can help, please do so.
  • hiwa

    #2
    Re: Problem with String.split(Re gex arg)

    blueoceanz1@hot mail.com (Blue Ocean) wrote in message news:<3349b232. 0402082118.25d2 [email protected] ogle.com>...[color=blue]
    > In short, it's not working right for me.
    >
    > In long:
    >
    > The program is designed to read numbers from an accumulator and speak
    > them out loud. Unfortunately, the class that contains the method to
    > read off large numbers is only for integers. My intention is to split
    > a String across the Regex of ".". However, this code does not work:
    >
    > private void doRealValueOf(S tring text) {
    > BBI beforeDot, afterDot;
    > String decArray[];
    >
    > decArray = text.split(".", 2);
    >
    > beforeDot = new BBI(decArray[0]);
    > afterDot = new BBI(decArray[1]);
    >
    > beforeDot.play( );
    > playString("poi nt.au");
    > sleep(400);
    > afterDot.play() ;
    > }
    >
    > Please assume as your read that all of the called methods except
    > text.split(".") works.
    >
    > I can _guarantee_ by use of a debugger that text does not have the
    > regex in more than one place. In my test case, "4.0", the output of
    > text.split(".") is
    >
    > text.split(".")
    > (java.lang.Stri ng[]) []
    >
    > I really cannot fathom why this might be the case.
    >
    > For reference, the output of the two argument split methods are as
    > follows:
    >
    > text.split(".", 0)
    > (java.lang.Stri ng[]) []
    > text.split(".", 1)
    > (java.lang.Stri ng[]) [4.0]
    > text.split(".", 2)
    > (java.lang.Stri ng[]) [, .0]
    >
    > And calling the toString method on the String text:
    >
    > text
    > (java.lang.Stri ng) 4.0
    >
    > These are all from the _exact same instant_ of the virtual machine;
    > the thread that all these variables are in is suspended, so there is
    > no chance of something being incorrect due to changes in the state of
    > the locals.
    >
    > Please help me. I'm starting to get desperate. I've been working on
    > this one problem for more than two hours now, and it is my only
    > roadblock to success. Anyone who can help, please do so.[/color]

    If you mean literal dot character, use "\." insteda of "." which
    is one of Java regular expression constructs.

    Comment

    • Blue Ocean

      #3
      Re: Problem with String.split(Re gex arg)

      HGA03630@nifty. ne.jp (hiwa) wrote in message news:<6869384d. 0402090239.3230 [email protected] ogle.com>...[color=blue]
      > If you mean literal dot character, use "\." insteda of "." which
      > is one of Java regular expression constructs.[/color]

      I don't know about yours, but my compiler gives me this error when I try to do that:

      Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )

      Any other ideas?

      Comment

      • Silvio Bierman

        #4
        Re: Problem with String.split(Re gex arg)

        use "\\."

        Silvio Bierman


        Comment

        • Gregory A. Swarthout

          #5
          Re: Problem with String.split(Re gex arg)

          blueoceanz1@hot mail.com (Blue Ocean) wrote in message news:<3349b232. 0402090721.6698 [email protected] ogle.com>...[color=blue]
          > HGA03630@nifty. ne.jp (hiwa) wrote in message news:<6869384d. 0402090239.3230 [email protected] ogle.com>...[color=green]
          > > If you mean literal dot character, use "\." insteda of "." which
          > > is one of Java regular expression constructs.[/color]
          >
          > I don't know about yours, but my compiler gives me this error when I try to do that:
          >
          > Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
          >
          > Any other ideas?[/color]

          [.]

          Comment

          • hiwa

            #6
            Re: Problem with String.split(Re gex arg)

            blueoceanz1@hot mail.com (Blue Ocean) wrote in message news:<3349b232. 0402090721.6698 [email protected] ogle.com>...[color=blue]
            > HGA03630@nifty. ne.jp (hiwa) wrote in message news:<6869384d. 0402090239.3230 [email protected] ogle.com>...[color=green]
            > > If you mean literal dot character, use "\." insteda of "." which
            > > is one of Java regular expression constructs.[/color]
            >
            > I don't know about yours, but my compiler gives me this error when I try to do that:
            >
            > Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
            >
            > Any other ideas?[/color]
            Oh! Very sorry!
            That is "\\.", not "\.". ... Then this is "\." at the regexp level.
            Sorry for my carelessness again.

            Comment

            Working...