Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2007, 10:51 PM
Member
 
Join Date: Nov 2007
Posts: 20
Gilgamesh is on a distinguished road
help w words
i have a text file and i want to read its words (and then use them to do something) ignoring the commas, dots, change of the line, spaces, etc. what should I do? (does java have any method that does this automatically?)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-20-2007, 11:27 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,191
hardwired is on a distinguished road
You can use String methods to break up the string into words.
You can use a StringTokenizer to break it into tokens; this is an older way.
You can use the split method to break up the string into an array of words. The challenge here is to use the correct Pattern. This is the newer way. See the Pattern class for options.
Maybe something like this:
Code:
String str = stringFromReadingInTheFile. String[] words = str.split("\\b(\\s+)\\b");
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-20-2007, 11:57 PM
Member
 
Join Date: Nov 2007
Posts: 20
Gilgamesh is on a distinguished road
is this difficult for my level man? should i avoid it?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-21-2007, 03:34 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,191
hardwired is on a distinguished road
I don't know.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-21-2007, 12:49 PM
Member
 
Join Date: Nov 2007
Posts: 20
Gilgamesh is on a distinguished road
\\b(\\s+)\\b what does this mean?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-21-2007, 07:15 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,191
hardwired is on a distinguished road
\\b(\\s+)\\b what does this mean
It's the (regular expression, aka regex) pattern that the split method will use to split up the string into an array.
The way to find out is to look up the (split) method in the String class api, scroll down to find the method in the Method Summary section, select the link to see the details about in the Method Detail section. At the end of the detail for split is a link to the Pattern class api where you can find out more info.
You can also find out more about RegularExpressions in Lesson: Regular Expressions.
If this is too much to deal with you can fall back to using methods in the String class which are introduced in Strings.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting words from a string using delimiters toad New To Java 4 07-07-2008 02:32 PM
The words *game* in java programming :confused: ibmzz Advanced Java 1 01-23-2008 10:23 AM
program help: Extracting words from a string toad New To Java 1 11-04-2007 07:39 PM
Analyze a string of words zoe Advanced Java 2 07-26-2007 11:01 AM
Aspose.Words for Java - 2.1.0.0 levent Java Announcements 0 05-24-2007 11:08 AM


All times are GMT +3. The time now is 10:46 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org