Tokenizing Problem...

9

9GB

Wait! I know how to tokenize a string, but I need it very frequently,
lets say after every word. I have a sequence like: "4 3,3 2.2 3|0(4)"
and I have to extract integers out of them. I can't be arsed to type
StringTokenizer() again and again for every token, is there anyway to
make life a little bit easier?
 
E

Eric Sosman

9GB wrote On 06/19/06 15:43,:
Wait! I know how to tokenize a string, but I need it very frequently,
lets say after every word. I have a sequence like: "4 3,3 2.2 3|0(4)"
and I have to extract integers out of them. I can't be arsed to type
StringTokenizer() again and again for every token, is there anyway to
make life a little bit easier?

String whole = "4 3,3 2.2 3|0(4)";
String[] pieces = whole.split("\\D+");

If you chop up a lot of different Strings with the
same regular expression, consider compiling the regex to
a Pattern just once and using it many times.
 
9

9GB

Eric said:
String whole = "4 3,3 2.2 3|0(4)";
String[] pieces = whole.split("\\D+");

If you chop up a lot of different Strings with the
same regular expression, consider compiling the regex to
a Pattern just once and using it many times.

Whats that ??? How does that works? I mean what's D in that pattern?
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

9GB schreef:
Eric said:
String whole = "4 3,3 2.2 3|0(4)";
String[] pieces = whole.split("\\D+");

If you chop up a lot of different Strings with the
same regular expression, consider compiling the regex to
a Pattern just once and using it many times.

Whats that ??? How does that works? I mean what's D in that pattern?

STFW: google java regex

Amongst others:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html

H.

- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEl7ZIe+7xMGD3itQRAqzMAJ4mrRBgjeToVCILUES8/btopwyX+wCeI/wT
D4rhNQSTUUne6mPpfEYX7Wo=
=LpPS
-----END PGP SIGNATURE-----
 
T

Thomas Fritsch

9GB said:
Eric said:
String whole = "4 3,3 2.2 3|0(4)";
String[] pieces = whole.split("\\D+");

If you chop up a lot of different Strings with the
same regular expression, consider compiling the regex to
a Pattern just once and using it many times.


Whats that ??? How does that works? I mean what's D in that pattern?
Read the API doc of the String's split(String) method
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#split(java.lang.String)>
and follow the links (concerning regular expressions) given there.
 
E

Eric Sosman

9GB wrote On 06/20/06 04:29,:
Eric said:
String whole = "4 3,3 2.2 3|0(4)";
String[] pieces = whole.split("\\D+");

If you chop up a lot of different Strings with the
same regular expression, consider compiling the regex to
a Pattern just once and using it many times.


Whats that ??? How does that works? I mean what's D in that pattern?

"Use the For-- er, the Javadoc, Luke."
 

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,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top