Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
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 12-01-2007, 11:06 PM
Member
 
Join Date: Nov 2007
Posts: 20
Gilgamesh is on a distinguished road
tokens
I am creating tokens using String Tokenizer from a input file (in order to compare these tokens to the elements of a String Array). But I got problem with the words than are hyphenated due to the change of the line (in the file). How can i unite the broken parts of these words (and then treat them as tokens ready to be tested)?

e.g. Java is a programming language origi-
nally developed by Sun Microsystems
and released in 1995 as a core compo-
nent of Sun's Java platform.

the '-' will still be part of the delimeters right?

Last edited by Gilgamesh : 12-01-2007 at 11:29 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-01-2007, 11:13 PM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Can you post some of your code? I dont understand what you are doing.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-01-2007, 11:48 PM
Member
 
Join Date: Nov 2007
Posts: 20
Gilgamesh is on a distinguished road
better now?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-02-2007, 12:28 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
I am not sure how you read the file and such. Also i just added the output to a vector for testing (output of the file that is).

Code:
BufferedReader rd = new BufferedReader(new FileReader( "test/test2.txt")); String s; String temp = ""; Vector<String> file = new Vector<String>(); while ((s = rd.readLine()) != null) { // if temp has a length, then we want to add it to the file, // with the line /* * this will check temp before executing the rest of the code * (obviously). that means temp will be appened on the next pass * (next line of the output): * ex: * foo * foo- * bar * * will become: * foo * foobar */ if (temp.length() > 0) file.add(temp + s); // checks if we have a hyphen at the end if (s.endsWith("-")) { // handles multple words. if it contains a space, it will // assume that the last space means its the word it needs to // combiine if (s.trim().contains(" ")) { temp = s.substring(s.trim().lastIndexOf(" ") + 1, s .trim().length() - 1); file.add(s.substring(0, s.trim().lastIndexOf(" "))); } else { // if there is no space, then we will just assume that it is a single word temp = s.substring(0, s.trim().length() - 1); } } else temp = ""; }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-02-2007, 03:07 AM
Member
 
Join Date: Nov 2007
Posts: 20
Gilgamesh is on a distinguished road
Using buffered reader, and then while not null the readLine() continues, then String Tokenizer creates the tokens (having as delimeters .,?;: etc).

So, I want not only the tokens that are defined thanks to the delimeters, but I also want to create tokens that are made by words that have a hyphen at the end of the line and continue into the next line.

(And then take each and every token (created by either of these two procedures, no matter by which) and do something with them.)

Last edited by Gilgamesh : 12-02-2007 at 03:09 AM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-03-2007, 01:30 AM
Member
 
Join Date: Nov 2007
Posts: 20
Gilgamesh is on a distinguished road
understood?
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
Getting tokens using Scanner class Java Tip Java Tips 0 02-05-2008 11:11 AM
How to use StringTokenizer for multiple tokens javaplus New To Java 2 11-29-2007 11:38 AM
tokens Gilgamesh New To Java 3 11-25-2007 04:39 AM


All times are GMT +3. The time now is 04:01 AM.


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