469,266 Members | 1,679 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

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(String text) {
BBI beforeDot, afterDot;
String decArray[];

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

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

beforeDot.play();
playString("point.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.String[]) []

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.String[]) []
text.split(".", 1)
(java.lang.String[]) [4.0]
text.split(".", 2)
(java.lang.String[]) [, .0]

And calling the toString method on the String text:

text
(java.lang.String) 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.
Jul 17 '05 #1
5 26886
bl*********@hotmail.com (Blue Ocean) wrote in message news:<33**************************@posting.google. com>...
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(String text) {
BBI beforeDot, afterDot;
String decArray[];

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

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

beforeDot.play();
playString("point.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.String[]) []

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.String[]) []
text.split(".", 1)
(java.lang.String[]) [4.0]
text.split(".", 2)
(java.lang.String[]) [, .0]

And calling the toString method on the String text:

text
(java.lang.String) 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.


If you mean literal dot character, use "\." insteda of "." which
is one of Java regular expression constructs.
Jul 17 '05 #2
HG******@nifty.ne.jp (hiwa) wrote in message news:<68**************************@posting.google. com>...
If you mean literal dot character, use "\." insteda of "." which
is one of Java regular expression constructs.


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?
Jul 17 '05 #3
use "\\."

Silvio Bierman
Jul 17 '05 #4
bl*********@hotmail.com (Blue Ocean) wrote in message news:<33**************************@posting.google. com>...
HG******@nifty.ne.jp (hiwa) wrote in message news:<68**************************@posting.google. com>...
If you mean literal dot character, use "\." insteda of "." which
is one of Java regular expression constructs.


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?


[.]
Jul 17 '05 #5
bl*********@hotmail.com (Blue Ocean) wrote in message news:<33**************************@posting.google. com>...
HG******@nifty.ne.jp (hiwa) wrote in message news:<68**************************@posting.google. com>...
If you mean literal dot character, use "\." insteda of "." which
is one of Java regular expression constructs.


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?

Oh! Very sorry!
That is "\\.", not "\.". ... Then this is "\." at the regexp level.
Sorry for my carelessness again.
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Martin Dieringer | last post: by
3 posts views Thread by Joe Fisherman | last post: by
14 posts views Thread by tom t/LA | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.