Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Tokenizing Problem...

Thread view: 
9GB - 19 Jun 2006 20:43 GMT
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?
Eric Sosman - 19 Jun 2006 21:07 GMT
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.

Signature

Eric.Sosman@sun.com

9GB - 20 Jun 2006 09:29 GMT
>     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?
Hendrik Maryns - 20 Jun 2006 09:48 GMT
9GB schreef:
>>     String whole = "4 3,3 2.2 3|0(4)";
>>     String[] pieces = whole.split("\\D+");
[quoted text clipped - 4 lines]
>
> 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
Thomas Fritsch - 20 Jun 2006 10:19 GMT
9GB schrieb:

>>    String whole = "4 3,3 2.2 3|0(4)";
>>    String[] pieces = whole.split("\\D+");
[quoted text clipped - 4 lines]
>
> 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.

Signature

Thomas

Eric Sosman - 20 Jun 2006 14:45 GMT
9GB wrote On 06/20/06 04:29,:

>>    String whole = "4 3,3 2.2 3|0(4)";
>>    String[] pieces = whole.split("\\D+");
[quoted text clipped - 4 lines]
>
> Whats that ??? How does that works? I mean what's D in that pattern?

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

Signature

Eric.Sosman@sun.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.