Results 1 to 6 of 6

Thread: help w words

  1. #1
    Gilgamesh is offline Member
    Join Date
    Nov 2007
    Posts
    20
    Rep Power
    0

    Default 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?)

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    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:
    Java Code:
    String str = stringFromReadingInTheFile.
    String[] words = str.split("\\b(\\s+)\\b");

  3. #3
    Gilgamesh is offline Member
    Join Date
    Nov 2007
    Posts
    20
    Rep Power
    0

    Default

    :eek: is this difficult for my level man? should i avoid it?

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    I don't know.

  5. #5
    Gilgamesh is offline Member
    Join Date
    Nov 2007
    Posts
    20
    Rep Power
    0

    Default

    \\b(\\s+)\\b what does this mean?

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    \\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.

Similar Threads

  1. Replies: 4
    Last Post: 07-07-2008, 02:32 PM
  2. The words *game* in java programming :confused:
    By ibmzz in forum Advanced Java
    Replies: 1
    Last Post: 01-23-2008, 10:23 AM
  3. program help: Extracting words from a string
    By toad in forum New To Java
    Replies: 1
    Last Post: 11-04-2007, 07:39 PM
  4. Analyze a string of words
    By zoe in forum Advanced Java
    Replies: 2
    Last Post: 07-26-2007, 11:01 AM
  5. Aspose.Words for Java - 2.1.0.0
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-24-2007, 11:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •