Regular expressions as string delimiter?

C

chad

We can simply construct a StringTokenizer by calling the constructor
that takes the String to be parsed and the string that represents the
delimiter.

But, suppose that I have a String like this:

"The university library has a collection of 237 books published in the
1830's in the United Kingdom."

I want to use, among others, the numeric numbers such as 237 and 1830
as delimiters also. Is such a delimiter possible in Java?
 
C

Carl Howells

chad said:
We can simply construct a StringTokenizer by calling the constructor
that takes the String to be parsed and the string that represents the
delimiter.

But, suppose that I have a String like this:

"The university library has a collection of 237 books published in the
1830's in the United Kingdom."

I want to use, among others, the numeric numbers such as 237 and 1830
as delimiters also. Is such a delimiter possible in Java?

The best solution to this is new as of jdk 1.5... The new
java.util.Scanner class is really an amazing improvement over all the
the previous formatted input classes in java. It's much more powerful
than StringTokenizer, and slightly more powerful

With jdk 1.4, you can use the split() method on Strings to get an array
based on a regular expression.

With jdk 1.3 and earlier, the standard libraries don't have anything to
support that, so you'll have to either write your own system, or use an
external product.
 
P

parv

The best solution to this is new as of jdk 1.5... The new
java.util.Scanner class is really an amazing improvement over all the
the previous formatted input classes in java. It's much more powerful
than StringTokenizer, and slightly more powerful

Did the last sentence cut off at the end, or is it my reader/server?


- parv
 
C

Carl Howells

parv said:
in message <[email protected]>,
wrote Carl Howells ...




Did the last sentence cut off at the end, or is it my reader/server?

Oops, that'll teach me to get distracted while sending out a message...

Finishing that thought:

It's much more powerful than StringTokenizer, and slightly more powerful
than StreamTokenizer with a *much* better API.
 
P

parv

Finishing that thought:

It's much more powerful than StringTokenizer, and slightly more
powerful than StreamTokenizer with a *much* better API.

Actually, that helps me too. I am currently using JDK 1.3, and
am currently working on something like a tokenized stream.

Thanks for finishing the thought.


- parv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top