473,378 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 27157
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Martin Dieringer | last post by:
I am trying to split a file by a fixed string. The file is too large to just read it into a string and split this. I could probably use a lexer but there maybe anything more simple? thanks m.
5
by: Jason | last post by:
Hi all basically its what i said in the subject. Would just like to know how to split a string using a STRING value as the delimeter and not a CHAR as the delimeter. Example: "I like Cheese",...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
3
by: Rico | last post by:
If there are consecutive occurrences of characters from the given delimiter, String.Split() and Regex.Split() produce an empty string as the token that's between such consecutive occurrences. It...
3
by: Joe Fisherman | last post by:
I have used regex to parse a huge text file, and grab a tab delimited portion of it. I often use comma delimited text files, and use Jet Oledb4. I read that I would need an ini if the file wasn't...
14
by: tom t/LA | last post by:
Here is a function to convert a CSV file to a Javascript array. Uses idealized file reading functions based on the std C library, since there is no Javascript standard. Not fully tested. ...
3
by: | last post by:
I'm analyzing large strings and finding matches using the Regex class. I want to find the context those matches are found in and to display excerpts of that context, just as a search engine might....
10
by: Mokita | last post by:
Hello, I am working with Taverna to build a workflow. Taverna has a beanshell where I can program in java. I am having some problems in writing a script. I want to extract information from a...
1
by: manjava | last post by:
hello, i want to know how can i invoke my method on web service with url contains String in the arguments Thanks
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.