By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 763 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

Problem with String.split(Regex arg)

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
use "\\."

Silvio Bierman
Jul 17 '05 #4

P: n/a
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

P: n/a
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.