• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hi

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following problem.
I have a sting with content. Using String Tokenizer how can i get 3 tokens. Token(here) - Each block of sentences which are separated by an blankline.
I am NN boy yar
am am a boy yar
a am NN boy yar
boy am NN boy yar
. am NP boy yar
I am goingI am going
I am goingI am going
I am goingI am going
Once am a boy 0
he am a boy 0
was am a boy 0
held am a boy 0
for t t t t

thanks and regds
Sobhan
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sobhan,
I guess u cannot do it with StringTokenizer.
 
Abdul Narayan D'souza TP
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sobhan,
I guess u cannot do it with StringTokenizer.
U could use LineNumberReader, and check if the returned line is blank.
Anyways u r in the wrong forum,this one deals puerly with "Threads and Synchronization"
Hey bartender where art thou.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As this particular festival of emoticons is wholly unrelated to "Threads and Synchronization" (the topic of this forum) I'll be moving it to "Java in General (Intermediate)." Followups there, please.
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sobhan,
I would break this problem down into smaller pieces. First, I'd forget about the file part: pretend you've already read in the information from the File, and just want to use StringTokenizer.
After you get that piece working, working on getting the information from the file, and feed it to the above method, which you already know works. Thus, try the following


Thus, first implement getTokens(). Then, after it's working perfectly, implement getFileContent()
Good luck,
M
 
Ranch Hand
Posts: 38
jQuery Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go to the Java API documentation at http://java.sun.com/j2se/1.4.2/docs/api/ and look up the StringTokenizer class. It's in the java.util package. If you write some code and it doesn't work, post it & people will help you figure out why.
 
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess is that your problem is beyond the vanilla implementation of the StringTokenizer because the StringTokenizer only works with single String characters acting as the delimiter. If you pass in a String with multiple characters it assumes that you want a tokenizer not based upon the character series, but that each character in the string is it's own separate delimiter character (i.e. you want to break on every instance of every character in the delimiter string).
In reality you want to break on the occurance of two newline characters in sequence (...or something like that). Because the StringTokenizer can only deal with delimiters made up of a single character, not the occurence of a set of characters in sequence, it won't work for you.
I've written my own StringTokenizer class that can use multi-character delimiters and I'm sure there are classes out there in open source that do similar things.
Good Luck,
 
Max Habibi
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Byron,
Unless I miss my guess, this is a homework assignment, so we can probably count well behaved data.
M
 
reply
    Bookmark Topic Watch Topic
  • New Topic